Skip to content

Commit

Permalink
Allow skipping conversion crd update
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Apr 3, 2024
1 parent fef5da9 commit 4e3636d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions webhook/resourcesemantics/conversion/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func newController(ctx context.Context, optsFunc ...OptionFunc) *controller.Impl
client: client,
secretLister: secretInformer.Lister(),
crdLister: crdInformer.Lister(),

skipReconcile: shouldSkipReconcile(ctx),
}

logger := logging.FromContext(ctx)
Expand Down Expand Up @@ -161,3 +163,18 @@ func newController(ctx context.Context, optsFunc ...OptionFunc) *controller.Impl

return c
}

type skipReconcileKey struct{}

func shouldSkipReconcile(ctx context.Context) bool {
v, ok := ctx.Value(skipReconcileKey{}).(*bool)
if ok && v != nil {
return *v
}
return false
}

// WithSkipReconcile returns a context with the skipReconcile value set
func WithSkipReconcile(ctx context.Context, skipReconcile *bool) context.Context {
return context.WithValue(ctx, skipReconcileKey{}, skipReconcile)
}
6 changes: 6 additions & 0 deletions webhook/resourcesemantics/conversion/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type reconciler struct {
secretLister corelisters.SecretLister
crdLister apixlisters.CustomResourceDefinitionLister
client apixclient.Interface

skipReconcile bool
}

var _ webhook.ConversionController = (*reconciler)(nil)
Expand All @@ -75,6 +77,10 @@ func (r *reconciler) Reconcile(ctx context.Context, key string) error {
return err
}

if r.skipReconcile { // delegate crd update externally, only validate the secret, contents might be filled in later
return nil
}

cacert, ok := secret.Data[certresources.CACert]
if !ok {
return fmt.Errorf("secret %q is missing %q key", r.secretName, certresources.CACert)
Expand Down

0 comments on commit 4e3636d

Please sign in to comment.