From d5ee4e64cd80ea41f5205d7df3e0006fe9becc1c Mon Sep 17 00:00:00 2001 From: pengli Date: Tue, 22 Jun 2021 22:00:20 +0800 Subject: [PATCH] Extend cluster.status.APIEnablements.Resources to struct with Kind Signed-off-by: pengli --- .../deploy/cluster.karmada.io_clusters.yaml | 17 +++++++++++++++-- pkg/apis/cluster/v1alpha1/types.go | 14 ++++++++++++-- .../cluster/v1alpha1/zz_generated.deepcopy.go | 18 +++++++++++++++++- .../status/cluster_status_controller.go | 11 ++++++++--- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/artifacts/deploy/cluster.karmada.io_clusters.yaml b/artifacts/deploy/cluster.karmada.io_clusters.yaml index 0198b2100..2813da346 100644 --- a/artifacts/deploy/cluster.karmada.io_clusters.yaml +++ b/artifacts/deploy/cluster.karmada.io_clusters.yaml @@ -149,9 +149,22 @@ spec: is for. type: string resources: - description: Resources contains the name of the resources. + description: Resources is a list of APIResource. items: - type: string + description: APIResource specifies the name and kind names + for the resource. + properties: + kind: + description: Kind is the kind for the resource (e.g. 'Deployment' + is the kind for resource 'deployments') + type: string + name: + description: Name is the plural name of the resource. + type: string + required: + - kind + - name + type: object type: array required: - groupVersion diff --git a/pkg/apis/cluster/v1alpha1/types.go b/pkg/apis/cluster/v1alpha1/types.go index 028485ddb..b83a8654e 100644 --- a/pkg/apis/cluster/v1alpha1/types.go +++ b/pkg/apis/cluster/v1alpha1/types.go @@ -138,9 +138,19 @@ type ClusterStatus struct { type APIEnablement struct { // GroupVersion is the group and version this APIEnablement is for. GroupVersion string `json:"groupVersion"` - // Resources contains the name of the resources. + // Resources is a list of APIResource. // +optional - Resources []string `json:"resources,omitempty"` + Resources []APIResource `json:"resources,omitempty"` +} + +// APIResource specifies the name and kind names for the resource. +type APIResource struct { + // Name is the plural name of the resource. + // +required + Name string `json:"name"` + // Kind is the kind for the resource (e.g. 'Deployment' is the kind for resource 'deployments') + // +required + Kind string `json:"kind"` } // NodeSummary represents the summary of nodes status in a specific cluster. diff --git a/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go index bcad3f141..08ac2a924 100644 --- a/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go @@ -15,7 +15,7 @@ func (in *APIEnablement) DeepCopyInto(out *APIEnablement) { *out = *in if in.Resources != nil { in, out := &in.Resources, &out.Resources - *out = make([]string, len(*in)) + *out = make([]APIResource, len(*in)) copy(*out, *in) } return @@ -31,6 +31,22 @@ func (in *APIEnablement) DeepCopy() *APIEnablement { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIResource) DeepCopyInto(out *APIResource) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResource. +func (in *APIResource) DeepCopy() *APIResource { + if in == nil { + return nil + } + out := new(APIResource) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Cluster) DeepCopyInto(out *Cluster) { *out = *in diff --git a/pkg/controllers/status/cluster_status_controller.go b/pkg/controllers/status/cluster_status_controller.go index e17142ab5..fbcc12435 100644 --- a/pkg/controllers/status/cluster_status_controller.go +++ b/pkg/controllers/status/cluster_status_controller.go @@ -370,11 +370,16 @@ func getAPIEnablements(clusterClient *util.ClusterClient) ([]v1alpha1.APIEnablem var apiEnablements []v1alpha1.APIEnablement for _, list := range apiResourceList { - var apiResource []string + var apiResources []v1alpha1.APIResource for _, resource := range list.APIResources { - apiResource = append(apiResource, resource.Name) + apiResource := v1alpha1.APIResource{ + Name: resource.Name, + Kind: resource.Kind, + } + + apiResources = append(apiResources, apiResource) } - apiEnablements = append(apiEnablements, v1alpha1.APIEnablement{GroupVersion: list.GroupVersion, Resources: apiResource}) + apiEnablements = append(apiEnablements, v1alpha1.APIEnablement{GroupVersion: list.GroupVersion, Resources: apiResources}) } return apiEnablements, nil