-
Notifications
You must be signed in to change notification settings - Fork 888
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
External etcd
Support for Karmada Operator - Part 1
#5699
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,15 @@ package karmada | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
"time" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/record" | ||
|
@@ -36,6 +40,7 @@ import ( | |
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
|
||
operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1" | ||
"github.com/karmada-io/karmada/operator/pkg/constants" | ||
operatorscheme "github.com/karmada-io/karmada/operator/pkg/scheme" | ||
) | ||
|
||
|
@@ -48,6 +53,9 @@ const ( | |
|
||
// DisableCascadingDeletionLabel is the label that determine whether to perform cascade deletion | ||
DisableCascadingDeletionLabel = "operator.karmada.io/disable-cascading-deletion" | ||
|
||
// ValidationErrorReason is the reason for a validation error | ||
ValidationErrorReason = "ValidationError" | ||
) | ||
|
||
// Controller controls the Karmada resource. | ||
|
@@ -77,6 +85,11 @@ func (ctrl *Controller) Reconcile(ctx context.Context, req controllerruntime.Req | |
return controllerruntime.Result{}, err | ||
} | ||
|
||
if err := ctrl.validateKarmada(karmada); err != nil { | ||
klog.Error(err, "Validation failed for karmada") | ||
return controllerruntime.Result{}, nil | ||
} | ||
|
||
// The object is being deleted | ||
if !karmada.DeletionTimestamp.IsZero() { | ||
val, ok := karmada.Labels[DisableCascadingDeletionLabel] | ||
|
@@ -96,6 +109,31 @@ func (ctrl *Controller) Reconcile(ctx context.Context, req controllerruntime.Req | |
return controllerruntime.Result{}, ctrl.syncKarmada(karmada) | ||
} | ||
|
||
// validateKarmada ensures the Karmada resource adheres to validation rules | ||
func (ctrl *Controller) validateKarmada(karmada *operatorv1alpha1.Karmada) error { | ||
if karmada.Spec.Components.Etcd != nil && karmada.Spec.Components.Etcd.External != nil { | ||
expectedSecretName := fmt.Sprintf("%s-%s", karmada.Name, constants.KarmadaApiserverEtcdClientCertNameSuffix) | ||
if karmada.Spec.Components.Etcd.External.SecretRef.Name != expectedSecretName { | ||
errorMessage := fmt.Sprintf("Secret name for external etcd client must be %s, but got %s", expectedSecretName, karmada.Spec.Components.Etcd.External.SecretRef.Name) | ||
ctrl.EventRecorder.Event(karmada, corev1.EventTypeWarning, ValidationErrorReason, errorMessage) | ||
|
||
newCondition := metav1.Condition{ | ||
Type: string(operatorv1alpha1.Ready), | ||
Status: metav1.ConditionFalse, | ||
Reason: ValidationErrorReason, | ||
Message: errorMessage, | ||
LastTransitionTime: metav1.Now(), | ||
} | ||
meta.SetStatusCondition(&karmada.Status.Conditions, newCondition) | ||
if err := ctrl.Status().Update(context.TODO(), karmada); err != nil { | ||
return err | ||
} | ||
return fmt.Errorf(errorMessage) | ||
} | ||
} | ||
return nil | ||
} | ||
Comment on lines
+112
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks good. It covers what we discussed perfectly. Just put some thoughts.
But it is no big deal, we can refactor it in the future too. It depends on you. |
||
|
||
func (ctrl *Controller) syncKarmada(karmada *operatorv1alpha1.Karmada) error { | ||
klog.V(2).InfoS("Reconciling karmada", "name", karmada.Name) | ||
planner, err := NewPlannerFor(karmada, ctrl.Client, ctrl.Config) | ||
|
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.
As we discussed at the community meeting, use it as a suffix or a whole name waiting for further exploration.
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.
@RainbowMango , to clarify, I'm fine with whatever naming convention is used . What I'm actually interested in is the support for running multiple
Karmada
instances in the same namespace and if that will break. Today, the operator has support for that, and we've been relying on that support for some uses cases we have. I added some data on this thread to showcase a scenario where that's been working for us in one of our management clusters.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.
Can you explain why you want to run multiple instances in the same namespace here?
@chaunceyjiang are you using it this way?
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.
Since we now support running multiple instances in the same namespace, there is no reason to disable it. I'm just curious why users might want to manage them in the same namespace, as I think putting each Karmada instance in a separate namespace is a simpler approach. E.g. each instance belongs to one team, which will help manage the quotas.
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.
That was helpful and gave me a lot of confidence. In the historical discussions, I remember we talked more about having one instance per namespace. Thanks.