diff --git a/apis/kueue/v1alpha1/multikueueconfig_types.go b/apis/kueue/v1alpha1/multikueueconfig_types.go index 1fa40fb5d5..db43b5390a 100644 --- a/apis/kueue/v1alpha1/multikueueconfig_types.go +++ b/apis/kueue/v1alpha1/multikueueconfig_types.go @@ -36,7 +36,7 @@ const ( SecretLocationType LocationType = "Secret" ) -type KubeconfigRef struct { +type KubeConfig struct { // Name of the cluster inside the given KubeConfig. Name string `json:"name"` @@ -51,19 +51,20 @@ type KubeconfigRef struct { } type MultiKueueClusterSpec struct { - KubeconfigRef KubeconfigRef `json:"kubeconfigRef"` + // Information how to connect to the cluster. + KubeConfig KubeConfig `json:"kubeconfigRef"` } type MultiKueueClusterStatus struct { Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` } -//+genclient -//+genclient:nonNamespaced -//+kubebuilder:object:root=true -//+kubebuilder:storageversion -//+kubebuilder:subresource:status -//+kubebuilder:resource:scope=Cluster +// +genclient +// +genclient:nonNamespaced +// +kubebuilder:object:root=true +// +kubebuilder:storageversion +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Cluster // MultiKueueCluster is the Schema for the multikueue API type MultiKueueCluster struct { @@ -74,7 +75,7 @@ type MultiKueueCluster struct { Status MultiKueueClusterStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // MultiKueueClusterList contains a list of MultiKueueCluster type MultiKueueClusterList struct { @@ -93,11 +94,11 @@ type MultiKueueConfigSpec struct { Clusters []string `json:"clusters"` } -//+genclient -//+genclient:nonNamespaced -//+kubebuilder:object:root=true -//+kubebuilder:storageversion -//+kubebuilder:resource:scope=Cluster +// +genclient +// +genclient:nonNamespaced +// +kubebuilder:object:root=true +// +kubebuilder:storageversion +// +kubebuilder:resource:scope=Cluster // MultiKueueConfig is the Schema for the multikueue API type MultiKueueConfig struct { @@ -107,7 +108,7 @@ type MultiKueueConfig struct { Spec MultiKueueConfigSpec `json:"spec,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // MultiKueueConfigList contains a list of MultiKueueConfig type MultiKueueConfigList struct { diff --git a/apis/kueue/v1alpha1/zz_generated.deepcopy.go b/apis/kueue/v1alpha1/zz_generated.deepcopy.go index cfd70d1936..8a32b2bf9f 100644 --- a/apis/kueue/v1alpha1/zz_generated.deepcopy.go +++ b/apis/kueue/v1alpha1/zz_generated.deepcopy.go @@ -27,16 +27,16 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KubeconfigRef) DeepCopyInto(out *KubeconfigRef) { +func (in *KubeConfig) DeepCopyInto(out *KubeConfig) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeconfigRef. -func (in *KubeconfigRef) DeepCopy() *KubeconfigRef { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeConfig. +func (in *KubeConfig) DeepCopy() *KubeConfig { if in == nil { return nil } - out := new(KubeconfigRef) + out := new(KubeConfig) in.DeepCopyInto(out) return out } @@ -103,7 +103,7 @@ func (in *MultiKueueClusterList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MultiKueueClusterSpec) DeepCopyInto(out *MultiKueueClusterSpec) { *out = *in - out.KubeconfigRef = in.KubeconfigRef + out.KubeConfig = in.KubeConfig } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiKueueClusterSpec. diff --git a/charts/kueue/templates/crd/kueue.x-k8s.io_multikueueclusters.yaml b/charts/kueue/templates/crd/kueue.x-k8s.io_multikueueclusters.yaml index 46af7d997c..696bdd72b3 100644 --- a/charts/kueue/templates/crd/kueue.x-k8s.io_multikueueclusters.yaml +++ b/charts/kueue/templates/crd/kueue.x-k8s.io_multikueueclusters.yaml @@ -47,6 +47,7 @@ spec: spec: properties: kubeconfigRef: + description: Information how to connect to the cluster. properties: location: description: Location of the KubeConfig. diff --git a/client-go/applyconfiguration/kueue/v1alpha1/kubeconfigref.go b/client-go/applyconfiguration/kueue/v1alpha1/kubeconfig.go similarity index 72% rename from client-go/applyconfiguration/kueue/v1alpha1/kubeconfigref.go rename to client-go/applyconfiguration/kueue/v1alpha1/kubeconfig.go index aaea3ff62f..aa492329e5 100644 --- a/client-go/applyconfiguration/kueue/v1alpha1/kubeconfigref.go +++ b/client-go/applyconfiguration/kueue/v1alpha1/kubeconfig.go @@ -21,24 +21,24 @@ import ( v1alpha1 "sigs.k8s.io/kueue/apis/kueue/v1alpha1" ) -// KubeconfigRefApplyConfiguration represents an declarative configuration of the KubeconfigRef type for use +// KubeConfigApplyConfiguration represents an declarative configuration of the KubeConfig type for use // with apply. -type KubeconfigRefApplyConfiguration struct { +type KubeConfigApplyConfiguration struct { Name *string `json:"name,omitempty"` Location *string `json:"location,omitempty"` LocationType *v1alpha1.LocationType `json:"locationType,omitempty"` } -// KubeconfigRefApplyConfiguration constructs an declarative configuration of the KubeconfigRef type for use with +// KubeConfigApplyConfiguration constructs an declarative configuration of the KubeConfig type for use with // apply. -func KubeconfigRef() *KubeconfigRefApplyConfiguration { - return &KubeconfigRefApplyConfiguration{} +func KubeConfig() *KubeConfigApplyConfiguration { + return &KubeConfigApplyConfiguration{} } // WithName sets the Name field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Name field is set to the value of the last call. -func (b *KubeconfigRefApplyConfiguration) WithName(value string) *KubeconfigRefApplyConfiguration { +func (b *KubeConfigApplyConfiguration) WithName(value string) *KubeConfigApplyConfiguration { b.Name = &value return b } @@ -46,7 +46,7 @@ func (b *KubeconfigRefApplyConfiguration) WithName(value string) *KubeconfigRefA // WithLocation sets the Location field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Location field is set to the value of the last call. -func (b *KubeconfigRefApplyConfiguration) WithLocation(value string) *KubeconfigRefApplyConfiguration { +func (b *KubeConfigApplyConfiguration) WithLocation(value string) *KubeConfigApplyConfiguration { b.Location = &value return b } @@ -54,7 +54,7 @@ func (b *KubeconfigRefApplyConfiguration) WithLocation(value string) *Kubeconfig // WithLocationType sets the LocationType field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the LocationType field is set to the value of the last call. -func (b *KubeconfigRefApplyConfiguration) WithLocationType(value v1alpha1.LocationType) *KubeconfigRefApplyConfiguration { +func (b *KubeConfigApplyConfiguration) WithLocationType(value v1alpha1.LocationType) *KubeConfigApplyConfiguration { b.LocationType = &value return b } diff --git a/client-go/applyconfiguration/kueue/v1alpha1/multikueueclusterspec.go b/client-go/applyconfiguration/kueue/v1alpha1/multikueueclusterspec.go index eb64f01800..af40891fc2 100644 --- a/client-go/applyconfiguration/kueue/v1alpha1/multikueueclusterspec.go +++ b/client-go/applyconfiguration/kueue/v1alpha1/multikueueclusterspec.go @@ -20,7 +20,7 @@ package v1alpha1 // MultiKueueClusterSpecApplyConfiguration represents an declarative configuration of the MultiKueueClusterSpec type for use // with apply. type MultiKueueClusterSpecApplyConfiguration struct { - KubeconfigRef *KubeconfigRefApplyConfiguration `json:"kubeconfigRef,omitempty"` + KubeConfig *KubeConfigApplyConfiguration `json:"kubeconfigRef,omitempty"` } // MultiKueueClusterSpecApplyConfiguration constructs an declarative configuration of the MultiKueueClusterSpec type for use with @@ -29,10 +29,10 @@ func MultiKueueClusterSpec() *MultiKueueClusterSpecApplyConfiguration { return &MultiKueueClusterSpecApplyConfiguration{} } -// WithKubeconfigRef sets the KubeconfigRef field in the declarative configuration to the given value +// WithKubeConfig sets the KubeConfig field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the KubeconfigRef field is set to the value of the last call. -func (b *MultiKueueClusterSpecApplyConfiguration) WithKubeconfigRef(value *KubeconfigRefApplyConfiguration) *MultiKueueClusterSpecApplyConfiguration { - b.KubeconfigRef = value +// If called multiple times, the KubeConfig field is set to the value of the last call. +func (b *MultiKueueClusterSpecApplyConfiguration) WithKubeConfig(value *KubeConfigApplyConfiguration) *MultiKueueClusterSpecApplyConfiguration { + b.KubeConfig = value return b } diff --git a/client-go/applyconfiguration/utils.go b/client-go/applyconfiguration/utils.go index 690ae44cdc..671a65e7c4 100644 --- a/client-go/applyconfiguration/utils.go +++ b/client-go/applyconfiguration/utils.go @@ -32,8 +32,8 @@ import ( func ForKind(kind schema.GroupVersionKind) interface{} { switch kind { // Group=kueue.x-k8s.io, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithKind("KubeconfigRef"): - return &kueuev1alpha1.KubeconfigRefApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("KubeConfig"): + return &kueuev1alpha1.KubeConfigApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("MultiKueueCluster"): return &kueuev1alpha1.MultiKueueClusterApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("MultiKueueClusterSpec"): diff --git a/config/components/crd/bases/kueue.x-k8s.io_multikueueclusters.yaml b/config/components/crd/bases/kueue.x-k8s.io_multikueueclusters.yaml index 3d15e011af..d934088e28 100644 --- a/config/components/crd/bases/kueue.x-k8s.io_multikueueclusters.yaml +++ b/config/components/crd/bases/kueue.x-k8s.io_multikueueclusters.yaml @@ -34,6 +34,7 @@ spec: spec: properties: kubeconfigRef: + description: Information how to connect to the cluster. properties: location: description: Location of the KubeConfig. diff --git a/pkg/controller/admissionchecks/multikueue/admissioncheck.go b/pkg/controller/admissionchecks/multikueue/admissioncheck.go index 9fc236b863..cbfe41d1db 100644 --- a/pkg/controller/admissionchecks/multikueue/admissioncheck.go +++ b/pkg/controller/admissionchecks/multikueue/admissioncheck.go @@ -65,12 +65,10 @@ func (a *ACReconciler) Reconcile(ctx context.Context, req reconcile.Request) (re return reconcile.Result{}, client.IgnoreNotFound(err) } - active := true inactiveReason := "" log.V(2).Info("Reconcile AdmissionCheck") if cfg, err := a.helper.ConfigFromRef(ctx, ac.Spec.Parameters); err != nil { - active = false inactiveReason = fmt.Sprintf("Cannot load the AdmissionChecks parameters: %s", err.Error()) } else { var missingClusters []string @@ -80,6 +78,7 @@ func (a *ACReconciler) Reconcile(ctx context.Context, req reconcile.Request) (re cluster := &kueuealpha.MultiKueueCluster{} err := a.client.Get(ctx, types.NamespacedName{Name: clusterName}, cluster) if client.IgnoreNotFound(err) != nil { + log.Error(err, "reading cluster", "multiKueueCluster", clusterName) return reconcile.Result{}, err } @@ -94,23 +93,18 @@ func (a *ACReconciler) Reconcile(ctx context.Context, req reconcile.Request) (re var messageParts []string if len(missingClusters) > 0 { - active = false messageParts = []string{fmt.Sprintf("Missing clusters: %v", missingClusters)} } if len(inactiveClusters) > 0 { - active = false messageParts = append(messageParts, fmt.Sprintf("Inactive clusters: %v", inactiveClusters)) } inactiveReason = strings.Join(messageParts, ", ") } newCondition := metav1.Condition{ - Type: kueue.AdmissionCheckActive, - Status: metav1.ConditionTrue, - Reason: "Active", - Message: "The admission check is active", + Type: kueue.AdmissionCheckActive, } - if active { + if len(inactiveReason) == 0 { newCondition.Status = metav1.ConditionTrue newCondition.Reason = "Active" newCondition.Message = "The admission check is active" @@ -167,7 +161,7 @@ func (m *mkConfigHandler) Create(ctx context.Context, event event.CreateEvent, q } if err := queueReconcileForConfigUsers(ctx, mkc.Name, m.client, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on create event", "multiKueueConfig", klog.KObj(mkc)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on create event", "multiKueueConfig", klog.KObj(mkc)) } } @@ -179,7 +173,7 @@ func (m *mkConfigHandler) Update(ctx context.Context, event event.UpdateEvent, q } if err := queueReconcileForConfigUsers(ctx, oldMKC.Name, m.client, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on update event", "multiKueueConfig", klog.KObj(oldMKC)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on update event", "multiKueueConfig", klog.KObj(oldMKC)) } } @@ -190,7 +184,7 @@ func (m *mkConfigHandler) Delete(ctx context.Context, event event.DeleteEvent, q } if err := queueReconcileForConfigUsers(ctx, mkc.Name, m.client, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on delete event", "multiKueueConfig", klog.KObj(mkc)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on delete event", "multiKueueConfig", klog.KObj(mkc)) } } @@ -201,7 +195,7 @@ func (m *mkConfigHandler) Generic(ctx context.Context, event event.GenericEvent, } if err := queueReconcileForConfigUsers(ctx, mkc.Name, m.client, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on generic event", "multiKueueConfig", klog.KObj(mkc)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on generic event", "multiKueueConfig", klog.KObj(mkc)) } } @@ -237,7 +231,7 @@ func (m *mkClusterHandler) Create(ctx context.Context, event event.CreateEvent, } if err := queueReconcileForConfigUsers(ctx, mkc.Name, m.client, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on create event", "multiKueueConfig", klog.KObj(mkc)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on create event", "multiKueueConfig", klog.KObj(mkc)) } } @@ -252,7 +246,7 @@ func (m *mkClusterHandler) Update(ctx context.Context, event event.UpdateEvent, newActive := apimeta.IsStatusConditionTrue(newMKC.Status.Conditions, kueuealpha.MultiKueueClusterActive) if oldActive != newActive { if err := m.queue(ctx, newMKC, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on update event", "multiKueueCluster", klog.KObj(oldMKC)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on update event", "multiKueueCluster", klog.KObj(oldMKC)) } } } @@ -264,7 +258,7 @@ func (m *mkClusterHandler) Delete(ctx context.Context, event event.DeleteEvent, } if err := m.queue(ctx, mkc, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on delete event", "multiKueueCluster", klog.KObj(mkc)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on delete event", "multiKueueCluster", klog.KObj(mkc)) } } @@ -275,7 +269,7 @@ func (m *mkClusterHandler) Generic(ctx context.Context, event event.GenericEvent } if err := m.queue(ctx, mkc, q); err != nil { - ctrl.LoggerFrom(ctx).V(5).Error(err, "Failure on generic event", "multiKueueCluster", klog.KObj(mkc)) + ctrl.LoggerFrom(ctx).V(2).Error(err, "Failure on generic event", "multiKueueCluster", klog.KObj(mkc)) } } diff --git a/pkg/controller/admissionchecks/multikueue/indexer.go b/pkg/controller/admissionchecks/multikueue/indexer.go index 8cc43bd02a..3ff9d2fb63 100644 --- a/pkg/controller/admissionchecks/multikueue/indexer.go +++ b/pkg/controller/admissionchecks/multikueue/indexer.go @@ -44,7 +44,7 @@ func getIndexUsingKubeConfigs(configNamespace string) func(obj client.Object) [] if !isCluster { return nil } - return []string{strings.Join([]string{configNamespace, cluster.Spec.KubeconfigRef.Location}, "/")} + return []string{strings.Join([]string{configNamespace, cluster.Spec.KubeConfig.Location}, "/")} } } diff --git a/pkg/controller/admissionchecks/multikueue/indexer_test.go b/pkg/controller/admissionchecks/multikueue/indexer_test.go index 99122b23e6..bc9bd8c52a 100644 --- a/pkg/controller/admissionchecks/multikueue/indexer_test.go +++ b/pkg/controller/admissionchecks/multikueue/indexer_test.go @@ -65,39 +65,31 @@ func getClientBuilder() (*fake.ClientBuilder, context.Context) { return builder, ctx } -func TestMultikueConfigUsingKubeconfig(t *testing.T) { +func TestListMultikueClustersUsingKubeconfig(t *testing.T) { cases := map[string]struct { - configs []*kueuealpha.MultiKueueCluster + clusters []*kueuealpha.MultiKueueCluster filter client.ListOption wantListError error wantList []string }{ "no clusters": { - configs: []*kueuealpha.MultiKueueCluster{ - { - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - Name: "name", - }, - }, - }, filter: client.MatchingFields{UsingKubeConfigs: TestNamespace + "/secret1"}, }, "single cluster, single match": { - configs: []*kueuealpha.MultiKueueCluster{ + clusters: []*kueuealpha.MultiKueueCluster{ utiltesting.MakeMultiKueueCluster("cluster1").Secret("", "secret1").Obj(), }, filter: client.MatchingFields{UsingKubeConfigs: TestNamespace + "/secret1"}, wantList: []string{"cluster1"}, }, "single cluster, no match": { - configs: []*kueuealpha.MultiKueueCluster{ + clusters: []*kueuealpha.MultiKueueCluster{ utiltesting.MakeMultiKueueCluster("cluster2").Secret("", "secret2").Obj(), }, filter: client.MatchingFields{UsingKubeConfigs: TestNamespace + "/secret1"}, }, "multiple clusters, single match": { - configs: []*kueuealpha.MultiKueueCluster{ + clusters: []*kueuealpha.MultiKueueCluster{ utiltesting.MakeMultiKueueCluster("cluster1").Secret("", "secret1").Obj(), utiltesting.MakeMultiKueueCluster("cluster2").Secret("", "secret2").Obj(), }, @@ -109,7 +101,7 @@ func TestMultikueConfigUsingKubeconfig(t *testing.T) { t.Run(name, func(t *testing.T) { builder, ctx := getClientBuilder() k8sclient := builder.Build() - for _, req := range tc.configs { + for _, req := range tc.clusters { if err := k8sclient.Create(ctx, req); err != nil { t.Errorf("Unable to create %s request: %v", client.ObjectKeyFromObject(req), err) } @@ -129,3 +121,60 @@ func TestMultikueConfigUsingKubeconfig(t *testing.T) { }) } } + +func TestListMultikueConfigsUsingMultikueueClusters(t *testing.T) { + cases := map[string]struct { + configs []*kueuealpha.MultiKueueConfig + filter client.ListOption + wantListError error + wantList []string + }{ + "no configs": { + filter: client.MatchingFields{UsingMultiKueueClusters: "cluster1"}, + }, + "single config, single match": { + configs: []*kueuealpha.MultiKueueConfig{ + utiltesting.MakeMultiKueueConfig("config1").Clusters("cluster1", "cluster2").Obj(), + }, + filter: client.MatchingFields{UsingMultiKueueClusters: "cluster2"}, + wantList: []string{"config1"}, + }, + "single config, no match": { + configs: []*kueuealpha.MultiKueueConfig{ + utiltesting.MakeMultiKueueConfig("config2").Clusters("cluster2").Obj(), + }, + filter: client.MatchingFields{UsingMultiKueueClusters: "cluster1"}, + }, + "multiple configs, single match": { + configs: []*kueuealpha.MultiKueueConfig{ + utiltesting.MakeMultiKueueConfig("config1").Clusters("cluster1", "cluster2").Obj(), + utiltesting.MakeMultiKueueConfig("config2").Clusters("cluster2").Obj(), + }, + filter: client.MatchingFields{UsingMultiKueueClusters: "cluster1"}, + wantList: []string{"config1"}, + }, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + builder, ctx := getClientBuilder() + k8sclient := builder.Build() + for _, config := range tc.configs { + if err := k8sclient.Create(ctx, config); err != nil { + t.Errorf("Unable to create %s config: %v", client.ObjectKeyFromObject(config), err) + } + } + + lst := &kueuealpha.MultiKueueConfigList{} + + gotListErr := k8sclient.List(ctx, lst, tc.filter) + if diff := cmp.Diff(tc.wantListError, gotListErr); diff != "" { + t.Errorf("unexpected list error (-want/+got):\n%s", diff) + } + + gotList := slices.Map(lst.Items, func(mkc *kueuealpha.MultiKueueConfig) string { return mkc.Name }) + if diff := cmp.Diff(tc.wantList, gotList, cmpopts.EquateEmpty(), cmpopts.SortSlices(func(a, b string) bool { return a < b })); diff != "" { + t.Errorf("unexpected list (-want/+got):\n%s", diff) + } + }) + } +} diff --git a/pkg/controller/admissionchecks/multikueue/multikueuecluster.go b/pkg/controller/admissionchecks/multikueue/multikueuecluster.go index 2116210520..23e25d630c 100644 --- a/pkg/controller/admissionchecks/multikueue/multikueuecluster.go +++ b/pkg/controller/admissionchecks/multikueue/multikueuecluster.go @@ -121,6 +121,9 @@ func (rc *remoteClient) queueWorkloadEvent(ctx context.Context, ev watch.Event) localWl := &kueue.Workload{} if err := rc.localClient.Get(ctx, client.ObjectKeyFromObject(wl), localWl); err == nil { + if !apierrors.IsNotFound(err) { + ctrl.LoggerFrom(ctx).Error(err, "reading local workload") + } rc.wlUpdateCh <- event.GenericEvent{Object: localWl} } } @@ -164,7 +167,7 @@ func (c *clustersReconciler) stopAndRemoveCluster(clusterName string) { } } -func (c *clustersReconciler) setRemoteClientConfig(clusterName string, kubeconfig []byte) error { +func (c *clustersReconciler) setRemoteClientConfig(ctx context.Context, clusterName string, kubeconfig []byte) error { c.lock.Lock() defer c.lock.Unlock() @@ -178,6 +181,7 @@ func (c *clustersReconciler) setRemoteClientConfig(clusterName string, kubeconfi } if err := client.setConfig(c.rootContext, kubeconfig); err != nil { + ctrl.LoggerFrom(ctx).Error(err, "reading local workload") delete(c.clients, clusterName) return err } @@ -194,6 +198,7 @@ func (a *clustersReconciler) controllerFor(acName string) (*remoteClient, bool) func (c *clustersReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { cluster := &kueuealpha.MultiKueueCluster{} + log := ctrl.LoggerFrom(ctx) err := c.client.Get(ctx, req.NamespacedName, cluster) if client.IgnoreNotFound(err) != nil { @@ -202,26 +207,27 @@ func (c *clustersReconciler) Reconcile(ctx context.Context, req reconcile.Reques if err != nil || !cluster.DeletionTimestamp.IsZero() { c.stopAndRemoveCluster(req.Name) - // notify ac reconcilere return reconcile.Result{}, nil } // get the kubeconfig - kubeConfig, retry, err := c.getKubeConfig(ctx, &cluster.Spec.KubeconfigRef) + kubeConfig, retry, err := c.getKubeConfig(ctx, &cluster.Spec.KubeConfig) if retry { return reconcile.Result{}, nil } if err != nil { + log.Error(err, "reading kubeconfig") return reconcile.Result{}, c.updateStatus(ctx, cluster, false, "BadConfig", err.Error()) } - if err := c.setRemoteClientConfig(cluster.Name, kubeConfig); err != nil { + if err := c.setRemoteClientConfig(ctx, cluster.Name, kubeConfig); err != nil { + log.Error(err, "setting kubeconfig") return reconcile.Result{}, c.updateStatus(ctx, cluster, false, "ClientConnectionFailed", err.Error()) } return reconcile.Result{}, c.updateStatus(ctx, cluster, true, "Active", "Connected") } -func (c *clustersReconciler) getKubeConfig(ctx context.Context, ref *kueuealpha.KubeconfigRef) ([]byte, bool, error) { +func (c *clustersReconciler) getKubeConfig(ctx context.Context, ref *kueuealpha.KubeConfig) ([]byte, bool, error) { sec := corev1.Secret{} secretObjKey := types.NamespacedName{ Namespace: c.configNamespace, diff --git a/pkg/util/testing/wrappers.go b/pkg/util/testing/wrappers.go index 8bb22faeef..20c11fc81b 100644 --- a/pkg/util/testing/wrappers.go +++ b/pkg/util/testing/wrappers.go @@ -790,7 +790,7 @@ func (mkc *MultiKueueClusterWrapper) Obj() *kueuealpha.MultiKueueCluster { } func (mkc *MultiKueueClusterWrapper) Secret(name, secretName string) *MultiKueueClusterWrapper { - mkc.Spec.KubeconfigRef = kueuealpha.KubeconfigRef{ + mkc.Spec.KubeConfig = kueuealpha.KubeConfig{ Name: name, Location: secretName, LocationType: kueuealpha.SecretLocationType,