-
Notifications
You must be signed in to change notification settings - Fork 0
fix: added wait functionality for portal secret #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ac4ea79
f27b782
19554ff
2ec28e0
9658aa4
cb24090
e7228e8
15376b1
c920b66
296dac5
7aa4739
ed947cb
e8f9bc6
400a9d1
2aee8fc
186131f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,21 +4,30 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "slices" | ||
| "time" | ||
|
|
||
| "github.com/kcp-dev/kcp/sdk/apis/cache/initialization" | ||
| kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" | ||
| "github.com/platform-mesh/golang-commons/controller/lifecycle/runtimeobject" | ||
| "github.com/platform-mesh/golang-commons/controller/lifecycle/subroutine" | ||
| "github.com/platform-mesh/golang-commons/errors" | ||
| "github.com/rs/zerolog/log" | ||
| corev1 "k8s.io/api/core/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager" | ||
| ) | ||
|
|
||
| const ( | ||
| portalClientSecretNamespace = "platform-mesh-system" | ||
| ) | ||
|
|
||
| type removeInitializer struct { | ||
| initializerName string | ||
| mgr mcmanager.Manager | ||
| runtimeClient client.Client | ||
| } | ||
|
|
||
| // Finalize implements subroutine.Subroutine. | ||
|
|
@@ -48,6 +57,24 @@ func (r *removeInitializer) Process(ctx context.Context, instance runtimeobject. | |
| return ctrl.Result{}, nil | ||
| } | ||
|
|
||
| // we need to wait untill keycloak crossplane provider creates a portal secret | ||
OlegErshov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| workspaceName := getWorkspaceName(lc) | ||
| if workspaceName == "" { | ||
| return ctrl.Result{}, errors.NewOperatorError(fmt.Errorf("failed to get workspace path"), true, false) | ||
| } | ||
OlegErshov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| secretName := fmt.Sprintf("portal-client-secret-%s", workspaceName) | ||
| key := types.NamespacedName{Name: secretName, Namespace: portalClientSecretNamespace} | ||
|
|
||
| var secret corev1.Secret | ||
| if err := r.runtimeClient.Get(ctx, key, &secret); err != nil { | ||
| if apierrors.IsNotFound(err) { | ||
| log.Info().Msg(fmt.Sprintf("realm secret %s is not ready yet, trying again", secretName)) | ||
| return ctrl.Result{RequeueAfter: 5 * time.Second}, nil | ||
|
||
| } | ||
| return ctrl.Result{}, errors.NewOperatorError(fmt.Errorf("failed to get secret %s: %w", secretName, err), true, true) | ||
| } | ||
|
|
||
| patch := client.MergeFrom(lc.DeepCopy()) | ||
|
|
||
| lc.Status.Initializers = initialization.EnsureInitializerAbsent(initializer, lc.Status.Initializers) | ||
|
|
@@ -60,10 +87,11 @@ func (r *removeInitializer) Process(ctx context.Context, instance runtimeobject. | |
| return ctrl.Result{}, nil | ||
| } | ||
|
|
||
| func NewRemoveInitializer(mgr mcmanager.Manager, initializerName string) *removeInitializer { | ||
| func NewRemoveInitializer(mgr mcmanager.Manager, initializerName string, runtimeClient client.Client) *removeInitializer { | ||
| return &removeInitializer{ | ||
| initializerName: initializerName, | ||
| mgr: mgr, | ||
| runtimeClient: runtimeClient, | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defensive nil check for runtimeClient to prevent panics.
If runtimeClient is ever nil, r.runtimeClient.Get will panic.
func (r *removeInitializer) Process(ctx context.Context, instance runtimeobject.RuntimeObject) (ctrl.Result, errors.OperatorError) { @@ - secretName := fmt.Sprintf("portal-client-secret-%s", workspaceName) + secretName := fmt.Sprintf("portal-client-secret-%s", workspaceName) key := types.NamespacedName{Name: secretName, Namespace: PortalClientSecretNamespace} + if r.runtimeClient == nil { + return ctrl.Result{}, errors.NewOperatorError(fmt.Errorf("runtime client is not configured"), false, true) + }🤖 Prompt for AI Agents