diff --git a/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml b/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml index 16814fa36fbf..7ef5e3503214 100644 --- a/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml +++ b/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml @@ -3724,6 +3724,19 @@ spec: status: description: Most recently observed status of the Karmada. properties: + apiServerService: + description: |- + APIServerService reports the location of the Karmada API server service which + can be used by third-party applications to discover the Karmada Service, e.g. + expose the service outside the cluster by Ingress. + properties: + name: + description: Name represents the name of the Karmada API Server + service. + type: string + required: + - name + type: object conditions: description: Conditions represents the latest available observations of a karmada's current state. diff --git a/operator/config/crds/operator.karmada.io_karmadas.yaml b/operator/config/crds/operator.karmada.io_karmadas.yaml index 16814fa36fbf..7ef5e3503214 100644 --- a/operator/config/crds/operator.karmada.io_karmadas.yaml +++ b/operator/config/crds/operator.karmada.io_karmadas.yaml @@ -3724,6 +3724,19 @@ spec: status: description: Most recently observed status of the Karmada. properties: + apiServerService: + description: |- + APIServerService reports the location of the Karmada API server service which + can be used by third-party applications to discover the Karmada Service, e.g. + expose the service outside the cluster by Ingress. + properties: + name: + description: Name represents the name of the Karmada API Server + service. + type: string + required: + - name + type: object conditions: description: Conditions represents the latest available observations of a karmada's current state. diff --git a/operator/pkg/apis/operator/v1alpha1/type.go b/operator/pkg/apis/operator/v1alpha1/type.go index adeed796a528..bbf0a8776310 100644 --- a/operator/pkg/apis/operator/v1alpha1/type.go +++ b/operator/pkg/apis/operator/v1alpha1/type.go @@ -694,6 +694,21 @@ type KarmadaStatus struct { // Conditions represents the latest available observations of a karmada's current state. // +optional Conditions []metav1.Condition `json:"conditions,omitempty"` + + // APIServerService reports the location of the Karmada API server service which + // can be used by third-party applications to discover the Karmada Service, e.g. + // expose the service outside the cluster by Ingress. + // +optional + APIServerService *APIServerService `json:"apiServerService,omitempty"` +} + +// APIServerService tells the location of Karmada API server service. +// Currently, it only includes the name of the service. The namespace +// of the service is the same as the namespace of the current Karmada object. +type APIServerService struct { + // Name represents the name of the Karmada API Server service. + // +required + Name string `json:"name"` } // LocalSecretReference is a reference to a secret within the enclosing diff --git a/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go b/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go index 5f727b7c73b7..c57aca85c33c 100644 --- a/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go +++ b/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go @@ -27,6 +27,22 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIServerService) DeepCopyInto(out *APIServerService) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIServerService. +func (in *APIServerService) DeepCopy() *APIServerService { + if in == nil { + return nil + } + out := new(APIServerService) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CRDTarball) DeepCopyInto(out *CRDTarball) { *out = *in @@ -649,6 +665,11 @@ func (in *KarmadaStatus) DeepCopyInto(out *KarmadaStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.APIServerService != nil { + in, out := &in.APIServerService, &out.APIServerService + *out = new(APIServerService) + **out = **in + } return } diff --git a/operator/pkg/controller/karmada/planner.go b/operator/pkg/controller/karmada/planner.go index b3455c322c74..c6418d8331ee 100644 --- a/operator/pkg/controller/karmada/planner.go +++ b/operator/pkg/controller/karmada/planner.go @@ -180,6 +180,9 @@ func (p *Planner) afterRunJob() error { Namespace: p.karmada.GetNamespace(), Name: util.AdminKubeconfigSecretName(p.karmada.GetName()), } + p.karmada.Status.APIServerService = &operatorv1alpha1.APIServerService{ + Name: util.KarmadaAPIServerName(p.karmada.GetName()), + } return p.Client.Status().Update(context.TODO(), p.karmada) } // if it is deInit workflow, the cr will be deleted with karmada is be deleted, so we need not to diff --git a/operator/pkg/controller/karmada/planner_test.go b/operator/pkg/controller/karmada/planner_test.go index 9377f114c018..0f564304cc7c 100644 --- a/operator/pkg/controller/karmada/planner_test.go +++ b/operator/pkg/controller/karmada/planner_test.go @@ -259,6 +259,13 @@ func TestAfterRunJob(t *testing.T) { if err := verifyJobInCommon(planner, metav1.ConditionTrue, conditionMsg, "Completed"); err != nil { return fmt.Errorf("failed to verify after run job, got error: %v", err) } + if planner.karmada.Status.APIServerService == nil { + return fmt.Errorf("expected API Server service ref to be set, but got nil") + } + expectedAPIServerName := util.KarmadaAPIServerName(karmada.GetName()) + if planner.karmada.Status.APIServerService.Name != expectedAPIServerName { + return fmt.Errorf("expected API Server service Name to be %s, but got %s", expectedAPIServerName, planner.karmada.Status.APIServerService.Name) + } return nil },