Skip to content

Commit cf4549c

Browse files
committed
feat(featuretoggles): add readiness checks for KCP RootShard and FrontProxy in Process method
On-behalf-of: @SAP [email protected] Signed-off-by: Angel Kafazov <[email protected]>
1 parent 433b69e commit cf4549c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

pkg/subroutines/featuretoggles.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ package subroutines
33
import (
44
"context"
55
"path/filepath"
6+
"time"
67

8+
pmconfig "github.com/platform-mesh/golang-commons/config"
79
"github.com/platform-mesh/golang-commons/controller/lifecycle/runtimeobject"
810
"github.com/platform-mesh/golang-commons/errors"
911
"github.com/platform-mesh/golang-commons/logger"
1012
corev1alpha1 "github.com/platform-mesh/platform-mesh-operator/api/v1alpha1"
1113
"github.com/platform-mesh/platform-mesh-operator/internal/config"
14+
kerrors "k8s.io/apimachinery/pkg/api/errors"
15+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
16+
"k8s.io/apimachinery/pkg/runtime/schema"
17+
"k8s.io/apimachinery/pkg/types"
1218
"k8s.io/client-go/rest"
1319
ctrl "sigs.k8s.io/controller-runtime"
1420
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -58,6 +64,41 @@ func (r *FeatureToggleSubroutine) Finalizers() []string { // coverage-ignore
5864

5965
func (r *FeatureToggleSubroutine) Process(ctx context.Context, runtimeObj runtimeobject.RuntimeObject) (ctrl.Result, errors.OperatorError) {
6066
log := logger.LoadLoggerFromContext(ctx).ChildLogger("subroutine", r.GetName())
67+
operatorCfg := pmconfig.LoadConfigFromContext(ctx).(config.OperatorConfig)
68+
69+
// Gate on KCP RootShard readiness
70+
rootShard := &unstructured.Unstructured{}
71+
rootShard.SetGroupVersionKind(schema.GroupVersionKind{Group: "operator.kcp.io", Version: "v1alpha1", Kind: "RootShard"})
72+
if err := r.client.Get(ctx, types.NamespacedName{
73+
Name: operatorCfg.KCP.RootShardName,
74+
Namespace: operatorCfg.KCP.Namespace,
75+
}, rootShard); err != nil || !MatchesCondition(rootShard, "Available") {
76+
log.Info().Msg("RootShard is not ready.. Retry in 5 seconds")
77+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
78+
}
79+
80+
// Gate on KCP FrontProxy readiness
81+
frontProxy := &unstructured.Unstructured{}
82+
frontProxy.SetGroupVersionKind(schema.GroupVersionKind{Group: "operator.kcp.io", Version: "v1alpha1", Kind: "FrontProxy"})
83+
if err := r.client.Get(ctx, types.NamespacedName{
84+
Name: operatorCfg.KCP.FrontProxyName,
85+
Namespace: operatorCfg.KCP.Namespace,
86+
}, frontProxy); err != nil || !MatchesCondition(frontProxy, "Available") {
87+
log.Info().Msg("FrontProxy is not ready.. Retry in 5 seconds")
88+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
89+
}
90+
91+
// Ensure the KCP admin secret exists before building kubeconfig
92+
if _, err := GetSecret(r.client, operatorCfg.KCP.ClusterAdminSecretName, operatorCfg.KCP.Namespace); err != nil {
93+
if kerrors.IsNotFound(err) {
94+
log.Info().
95+
Str("secret", operatorCfg.KCP.ClusterAdminSecretName).
96+
Str("namespace", operatorCfg.KCP.Namespace).
97+
Msg("KCP admin secret not found yet.. Retry in 5 seconds")
98+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
99+
}
100+
return ctrl.Result{}, errors.NewOperatorError(err, true, true)
101+
}
61102

62103
inst := runtimeObj.(*corev1alpha1.PlatformMesh)
63104
for _, ft := range inst.Spec.FeatureToggles {

0 commit comments

Comments
 (0)