Skip to content

Commit

Permalink
some prints and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
daanvinken committed Nov 14, 2023
1 parent 054c850 commit 0bfc130
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions examples/sample/user.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apiVersion: ceph.radosgw.crossplane.io/v1alpha1
kind: CephUser
metadata:
name: my-ceph-user2
name: my-ceph-user-b
spec:
deletionPolicy: Delete
forProvider:
displayedName: john_doe2
uid: johndoe1232
displayedName: my-ceph-user-b
uid: myuser-b
userQuotaMaxBuckets: 5
userQuotaMaxObjects: 1000
userQuotaMaxSizeKB: 204800
Expand Down
27 changes: 17 additions & 10 deletions internal/controller/cephuser/cephuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ const (
inUseFinalizer = "cephuser-in-use.ceph.radosgw.crossplane.io"
)

// A NoOpService does nothing.
type NoOpService struct{}

var (
newNoOpService = func(_ []byte) (interface{}, error) { return &NoOpService{}, nil }
)

// Setup adds a controller that reconciles CephUser managed resources.
func Setup(mgr ctrl.Manager, o controller.Options) error {
name := managed.ControllerName(v1alpha1.CephUserGroupKind)
Expand All @@ -85,7 +78,6 @@ func Setup(mgr ctrl.Manager, o controller.Options) error {
managed.WithExternalConnecter(&connector{
kube: mgr.GetClient(),
usage: resource.NewProviderConfigUsageTracker(mgr.GetClient(), &apisv1alpha1.ProviderConfigUsage{}),
newServiceFn: newNoOpService,
vaultAdminClient: vaultAdminClient,
scheme: mgr.GetScheme(),
log: o.Logger.WithValues("controller", name)}),
Expand Down Expand Up @@ -125,6 +117,9 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.New(errNotCephUser)
}

// These fmt statements should be removed in the real implementation.
fmt.Printf("Connecting: %+v\n", cr.Name)

if err := c.usage.Track(ctx, mg); err != nil {
return nil, errors.Wrap(err, errTrackPCUsage)
}
Expand Down Expand Up @@ -155,7 +150,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
if err != nil {
return nil, errors.Wrap(err, errNewClient)
}

fmt.Printf("Creating new vault client for '%s'\n", cr.Name)
vaultClient, err := credentials.NewVaultClient(pc.Spec.CredentialsVault)
if err != nil {
return nil, errors.Wrap(err, "failed to create vault client for storing ceph credentials")
Expand Down Expand Up @@ -184,6 +179,9 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, errors.New(errNotCephUser)
}

// These fmt statements should be removed in the real implementation.
fmt.Printf("Observing: %+v\n", cr.Name)

// Create a new context and cancel it when we have either found the user or cannot find it.
ctxC, cancel := context.WithCancel(ctx)
defer cancel()
Expand Down Expand Up @@ -227,6 +225,9 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
return managed.ExternalCreation{}, errors.New(errNotCephUser)
}

// These fmt statements should be removed in the real implementation.
fmt.Printf("Creating: %+v\n", cr.Name)

user := radosgw.GenerateCephUserInput(cr)
_, err := c.rgwClient.CreateUser(ctx, *user)
if resource.Ignore(isAlreadyExists, err) != nil {
Expand Down Expand Up @@ -280,11 +281,14 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
}

func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) {
_, ok := mg.(*v1alpha1.CephUser)
cr, ok := mg.(*v1alpha1.CephUser)
if !ok {
return managed.ExternalUpdate{}, errors.New(errNotCephUser)
}

// These fmt statements should be removed in the real implementation.
fmt.Printf("Updating: %+v\n", cr.Name)

c.log.Debug("Updating CRD but not implemented.")

return managed.ExternalUpdate{
Expand All @@ -300,6 +304,9 @@ func (c *external) Delete(ctx context.Context, mg resource.Managed) error {
return errors.New(errNotCephUser)
}

// These fmt statements should be removed in the real implementation.
fmt.Printf("Deleting: %+v\n", cr.Name)

// Radosgw also doesn't allow removal if the user has buckets.
// TODO Still I think we shouldn't just trust this
if controllerutil.RemoveFinalizer(cr, inUseFinalizer) {
Expand Down

0 comments on commit 0bfc130

Please sign in to comment.