Skip to content

Commit

Permalink
Merge pull request #51 from vshn/add-endpoint-to-bucket
Browse files Browse the repository at this point in the history
Add "endpoint" field to bucket
  • Loading branch information
davidgubler authored Oct 26, 2022
2 parents daa008b + 971bae2 commit a44c5a3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions apis/cloudscale/v1/bucket_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ type BucketParameters struct {

// +kubebuilder:validation:Required

// EndpointURL is the URL where to create the bucket.
// If the scheme is omitted (`http/s`), HTTPS is assumed.
// Changing the endpoint after initial creation might have no effect.
EndpointURL string `json:"endpointURL"`
// Deprecated: Only here for compatibility with legacy Bucket objects
EndpointURL string `json:"endpointURL,omitempty"`

// BucketName is the name of the bucket to create.
// Defaults to `metadata.name` if unset.
Expand Down Expand Up @@ -80,6 +78,8 @@ type BucketObservation struct {
// BucketStatus represents the observed state of a Bucket.
type BucketStatus struct {
xpv1.ResourceStatus `json:",inline"`
Endpoint string `json:"endpoint,omitempty"`
EndpointURL string `json:"endpointURL,omitempty"`
AtProvider BucketObservation `json:"atProvider,omitempty"`
}

Expand Down
1 change: 0 additions & 1 deletion generate_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func newBucketSample() *cloudscalev1.Bucket {
Name: "my-cloudscale-user-credentials",
Namespace: "default",
},
EndpointURL: "objects.rma.cloudscale.ch",
BucketName: "my-provider-test-bucket",
Region: "rma",
BucketDeletionPolicy: cloudscalev1.DeleteAll,
Expand Down
12 changes: 10 additions & 2 deletions operator/bucketcontroller/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ type connectContext struct {
credentialsSecret *corev1.Secret
}

// Connect implements managed.ExternalConnecter.
func getEndpoint(bucket *cloudscalev1.Bucket) string {
return fmt.Sprintf("objects.%s.cloudscale.ch", bucket.Spec.ForProvider.Region)
}

func getEndpointURL(bucket *cloudscalev1.Bucket) string {
return fmt.Sprintf("https://%s", getEndpoint(bucket))
}

// Connect implements managed.ExternalConnector.
func (c *bucketConnector) Connect(ctx context.Context, mg resource.Managed) (managed.ExternalClient, error) {
ctx = pipeline.MutableContext(ctx)
log := controllerruntime.LoggerFrom(ctx)
Expand Down Expand Up @@ -103,7 +111,7 @@ func (c *bucketConnector) createS3Client(ctx *connectContext) error {
secret := ctx.credentialsSecret
bucket := ctx.bucket

parsed, err := url.Parse(bucket.Spec.ForProvider.EndpointURL)
parsed, err := url.Parse(getEndpointURL(bucket))
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions operator/bucketcontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (p *ProvisioningPipeline) Observe(ctx context.Context, mg resource.Managed)
s3Client := p.minio
bucket := fromManaged(mg)

bucket.Status.Endpoint = getEndpoint(bucket)
bucket.Status.EndpointURL = getEndpointURL(bucket)

bucketName := bucket.GetBucketName()
exists, err := bucketExistsFn(ctx, s3Client, bucketName)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions package/crds/cloudscale.crossplane.io_buckets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ spec:
type: object
x-kubernetes-map-type: atomic
endpointURL:
description: EndpointURL is the URL where to create the bucket.
If the scheme is omitted (`http/s`), HTTPS is assumed. Changing
the endpoint after initial creation might have no effect.
description: 'Deprecated: Only here for compatibility with legacy
Bucket objects'
type: string
region:
description: Region is the name of the region where the bucket
Expand All @@ -117,7 +116,6 @@ spec:
type: string
required:
- credentialsSecretRef
- endpointURL
- region
type: object
providerConfigRef:
Expand Down Expand Up @@ -334,6 +332,10 @@ spec:
- type
type: object
type: array
endpoint:
type: string
endpointURL:
type: string
type: object
required:
- spec
Expand Down
2 changes: 0 additions & 2 deletions samples/admission.k8s.io_admissionreview.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"name": "my-cloudscale-user-credentials",
"namespace": "default"
},
"endpointURL": "objects.rma.cloudscale.ch",
"bucketName": "another",
"region": "rma",
"bucketDeletionPolicy": "DeleteAll"
Expand All @@ -67,7 +66,6 @@
"name": "my-cloudscale-user-credentials",
"namespace": "default"
},
"endpointURL": "objects.rma.cloudscale.ch",
"bucketName": "my-provider-test-bucket",
"region": "rma",
"bucketDeletionPolicy": "DeleteAll"
Expand Down
1 change: 0 additions & 1 deletion samples/cloudscale.crossplane.io_bucket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ spec:
credentialsSecretRef:
name: my-cloudscale-user-credentials
namespace: default
endpointURL: objects.rma.cloudscale.ch
region: rma
status:
atProvider: {}
3 changes: 2 additions & 1 deletion test/e2e/provider/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
credentialsSecretRef:
name: objectsuser-credentials-e2e-test-kuttl
namespace: default
endpointURL: objects.rma.cloudscale.ch
region: rma
status:
atProvider:
Expand All @@ -28,4 +27,6 @@ status:
- type: Synced
status: 'True'
reason: ReconcileSuccess
endpoint: objects.rma.cloudscale.ch
endpointURL: https://objects.rma.cloudscale.ch
---
1 change: 0 additions & 1 deletion test/e2e/provider/01-install-bucket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ spec:
credentialsSecretRef:
name: objectsuser-credentials-e2e-test-kuttl
namespace: default
endpointURL: objects.rma.cloudscale.ch
region: rma
---

0 comments on commit a44c5a3

Please sign in to comment.