Skip to content

Commit

Permalink
put bucket status update into observe()
Browse files Browse the repository at this point in the history
  • Loading branch information
David Gubler committed Oct 25, 2022
1 parent cc3a006 commit 8d56cb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 10 additions & 4 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 All @@ -48,8 +56,6 @@ func (c *bucketConnector) Connect(ctx context.Context, mg resource.Managed) (man
return &NoopClient{}, nil
}

bucket.Status.Endpoint = fmt.Sprintf("objects.%s.cloudscale.ch", bucket.Spec.ForProvider.Region)
bucket.Status.EndpointURL = fmt.Sprintf("https://%s", bucket.Status.Endpoint)
pctx := &connectContext{Context: ctx, bucket: bucket}
pipe := pipeline.NewPipeline[*connectContext]()
pipe.WithBeforeHooks(pipelineutil.DebugLogger(pctx)).
Expand Down Expand Up @@ -105,7 +111,7 @@ func (c *bucketConnector) createS3Client(ctx *connectContext) error {
secret := ctx.credentialsSecret
bucket := ctx.bucket

parsed, err := url.Parse(bucket.Status.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

0 comments on commit 8d56cb1

Please sign in to comment.