From bb499fc0005f61a34c1770f8e94ab26be121e80b Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Mon, 13 Jan 2025 11:44:19 +0600 Subject: [PATCH] Report pod and storage resource via generic resource Signed-off-by: Tamal Saha --- .config/api-rules/violation_exceptions.list | 34 ++---- apis/core/v1alpha1/generic_resource_types.go | 29 ++++- apis/core/v1alpha1/openapi_generated.go | 96 ++++++++++++++++- apis/core/v1alpha1/zz_generated.deepcopy.go | 50 +++++++++ ...ore.k8s.appscode.com_genericresources.yaml | 102 ++++++++++++++++++ 5 files changed, 284 insertions(+), 27 deletions(-) diff --git a/.config/api-rules/violation_exceptions.list b/.config/api-rules/violation_exceptions.list index a407c5f37..8c9618996 100644 --- a/.config/api-rules/violation_exceptions.list +++ b/.config/api-rules/violation_exceptions.list @@ -41,6 +41,13 @@ API rule violation: list_type_missing,kmodules.xyz/offshoot-api/api/v1,PodSpec,V API rule violation: list_type_missing,kmodules.xyz/offshoot-api/api/v1,ServiceSpec,ExternalIPs API rule violation: list_type_missing,kmodules.xyz/offshoot-api/api/v1,ServiceSpec,LoadBalancerSourceRanges API rule violation: list_type_missing,kmodules.xyz/offshoot-api/api/v1,ServiceSpec,Ports +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,ControlPlaneInfo,DNSNames +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,ControlPlaneInfo,EmailAddresses +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,ControlPlaneInfo,IPAddresses +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,ControlPlaneInfo,URIs +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,SelfSubjectNamespaceAccessReviewSpec,NonResourceAttributes +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,SelfSubjectNamespaceAccessReviewSpec,ResourceAttributes +API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,SubjectAccessNamespaceReviewStatus,Namespaces API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,Action,Icons API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,ActionGroup,Items API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,ActionTemplate,Icons @@ -52,30 +59,6 @@ API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,UIParameterTemplate,InstanceLabelPaths API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,UIParameters,Actions API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/shared,UIParameters,InstanceLabelPaths -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ActionTemplate,Icons -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ActionTemplateGroup,Items -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ChartInfo,ValuesFiles -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,Dashboard,Panels -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,Dashboard,Vars -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,DependentFeatureSet,Features -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,Dependents,FeatureSets -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,FeatureSetSpec,Icons -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,FeatureSetSpec,RequiredFeatures -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,FeatureSetStatus,Features -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,FeatureSpec,Icons -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,FeatureSpec,ValuesFrom -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ReadinessChecks,Resources -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ReadinessChecks,Workloads -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,Requirements,Features -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceDashboardSpec,Dashboards -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceEditorSpec,Icons -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceEditorSpec,Variants -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceOutlineFilterSpec,Actions -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourceOutlineFilterSpec,Pages -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ResourcePageOutlineFilter,Sections -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,UIParameters,Actions -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,UIParameters,InstanceLabelPaths -API rule violation: list_type_missing,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,VariantRef,Icons API rule violation: names_match,k8s.io/api/core/v1,AzureDiskVolumeSource,DataDiskURI API rule violation: names_match,k8s.io/api/core/v1,ContainerStatus,LastTerminationState API rule violation: names_match,k8s.io/api/core/v1,DaemonEndpoint,Port @@ -124,7 +107,8 @@ API rule violation: names_match,kmodules.xyz/client-go/api/v1,TimeOfDay,Time API rule violation: names_match,kmodules.xyz/offshoot-api/api/v1,ContainerRuntimeSettings,IONice API rule violation: names_match,kmodules.xyz/offshoot-api/api/v1,VolumeSource,CephFS API rule violation: names_match,kmodules.xyz/offshoot-api/api/v1,VolumeSource,StorageOS +API rule violation: names_match,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,ControlPlaneInfo,URIs +API rule violation: names_match,kmodules.xyz/resource-metadata/apis/identity/v1alpha1,InboxTokenRequestResponse,AgentJWTToken API rule violation: names_match,kmodules.xyz/resource-metadata/apis/shared,Action,OperationID API rule violation: names_match,kmodules.xyz/resource-metadata/apis/shared,ActionTemplate,OperationID API rule violation: names_match,kmodules.xyz/resource-metadata/apis/shared,RegistryProxies,AppsCode -API rule violation: names_match,kmodules.xyz/resource-metadata/apis/ui/v1alpha1,ActionTemplate,OperationID diff --git a/apis/core/v1alpha1/generic_resource_types.go b/apis/core/v1alpha1/generic_resource_types.go index 65d53a196..564b1a6e5 100644 --- a/apis/core/v1alpha1/generic_resource_types.go +++ b/apis/core/v1alpha1/generic_resource_types.go @@ -68,7 +68,34 @@ type GenericResourceSpec struct { RoleResourceLimits map[api.PodRole]core.ResourceList `json:"roleResourceLimits,omitempty"` // +optional RoleResourceRequests map[api.PodRole]core.ResourceList `json:"roleResourceRequests,omitempty"` - Status GenericResourceStatus `json:"status"` + + Pods []ComputeResource `json:"pods,omitempty"` + Storage []StorageResource `json:"storage,omitempty"` + + Status GenericResourceStatus `json:"status"` +} + +type ComputeResource struct { + Name string `json:"name"` + // +optional + CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"` + Containers []ContainerResource `json:"containers,omitempty"` + InitContainers []ContainerResource `json:"initContainers,omitempty"` +} + +type ContainerResource struct { + Name string `json:"name"` + // +optional + Resource core.ResourceRequirements `json:"resource"` + RestartPolicy *core.ContainerRestartPolicy `json:"restartPolicy,omitempty"` +} + +type StorageResource struct { + Name string `json:"name"` + // +optional + CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"` + // +optional + Resources core.VolumeResourceRequirements `json:"resources,omitempty"` } type GenericResourceStatus struct { diff --git a/apis/core/v1alpha1/openapi_generated.go b/apis/core/v1alpha1/openapi_generated.go index cd51ef46c..1f1eb106f 100644 --- a/apis/core/v1alpha1/openapi_generated.go +++ b/apis/core/v1alpha1/openapi_generated.go @@ -358,6 +358,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kmodules.xyz/offshoot-api/api/v1.ServiceTemplateSpec": schema_kmodulesxyz_offshoot_api_api_v1_ServiceTemplateSpec(ref), "kmodules.xyz/offshoot-api/api/v1.Volume": schema_kmodulesxyz_offshoot_api_api_v1_Volume(ref), "kmodules.xyz/offshoot-api/api/v1.VolumeSource": schema_kmodulesxyz_offshoot_api_api_v1_VolumeSource(ref), + "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ComputeResource": schema_resource_metadata_apis_core_v1alpha1_ComputeResource(ref), "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ContainerView": schema_resource_metadata_apis_core_v1alpha1_ContainerView(ref), "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ControlPlaneInfo": schema_resource_metadata_apis_core_v1alpha1_ControlPlaneInfo(ref), "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ExecServiceFacilitator": schema_resource_metadata_apis_core_v1alpha1_ExecServiceFacilitator(ref), @@ -384,6 +385,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ResourceSummarySpec": schema_resource_metadata_apis_core_v1alpha1_ResourceSummarySpec(ref), "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ResourceView": schema_resource_metadata_apis_core_v1alpha1_ResourceView(ref), "kmodules.xyz/resource-metadata/apis/core/v1alpha1.Service": schema_resource_metadata_apis_core_v1alpha1_Service(ref), + "kmodules.xyz/resource-metadata/apis/core/v1alpha1.StorageResource": schema_resource_metadata_apis_core_v1alpha1_StorageResource(ref), "kmodules.xyz/resource-metadata/apis/shared.Action": schema_kmodulesxyz_resource_metadata_apis_shared_Action(ref), "kmodules.xyz/resource-metadata/apis/shared.ActionGroup": schema_kmodulesxyz_resource_metadata_apis_shared_ActionGroup(ref), "kmodules.xyz/resource-metadata/apis/shared.ActionInfo": schema_kmodulesxyz_resource_metadata_apis_shared_ActionInfo(ref), @@ -18869,6 +18871,39 @@ func schema_kmodulesxyz_offshoot_api_api_v1_VolumeSource(ref common.ReferenceCal } } +func schema_resource_metadata_apis_core_v1alpha1_ComputeResource(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "creationTimestamp": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), + }, + }, + "resource": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/api/core/v1.ResourceRequirements"), + }, + }, + }, + Required: []string{"name"}, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + } +} + func schema_resource_metadata_apis_core_v1alpha1_ContainerView(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -19738,6 +19773,32 @@ func schema_resource_metadata_apis_core_v1alpha1_GenericResourceSpec(ref common. }, }, }, + "pods": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("kmodules.xyz/resource-metadata/apis/core/v1alpha1.ComputeResource"), + }, + }, + }, + }, + }, + "storage": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("kmodules.xyz/resource-metadata/apis/core/v1alpha1.StorageResource"), + }, + }, + }, + }, + }, "status": { SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, @@ -19749,7 +19810,7 @@ func schema_resource_metadata_apis_core_v1alpha1_GenericResourceSpec(ref common. }, }, Dependencies: []string{ - "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/apimachinery/pkg/api/resource.Quantity", "kmodules.xyz/client-go/api/v1.ClusterMetadata", "kmodules.xyz/client-go/api/v1.ResourceID", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.GenericResourceStatus"}, + "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/apimachinery/pkg/api/resource.Quantity", "kmodules.xyz/client-go/api/v1.ClusterMetadata", "kmodules.xyz/client-go/api/v1.ResourceID", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ComputeResource", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.GenericResourceStatus", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.StorageResource"}, } } @@ -20365,6 +20426,39 @@ func schema_resource_metadata_apis_core_v1alpha1_Service(ref common.ReferenceCal } } +func schema_resource_metadata_apis_core_v1alpha1_StorageResource(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "creationTimestamp": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), + }, + }, + "resources": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/api/core/v1.VolumeResourceRequirements"), + }, + }, + }, + Required: []string{"name"}, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.VolumeResourceRequirements", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + } +} + func schema_kmodulesxyz_resource_metadata_apis_shared_Action(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/apis/core/v1alpha1/zz_generated.deepcopy.go b/apis/core/v1alpha1/zz_generated.deepcopy.go index 11e2efb72..20cb7c7e4 100644 --- a/apis/core/v1alpha1/zz_generated.deepcopy.go +++ b/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -34,6 +34,24 @@ import ( version "k8s.io/apimachinery/pkg/version" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComputeResource) DeepCopyInto(out *ComputeResource) { + *out = *in + in.CreationTimestamp.DeepCopyInto(&out.CreationTimestamp) + in.Resource.DeepCopyInto(&out.Resource) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComputeResource. +func (in *ComputeResource) DeepCopy() *ComputeResource { + if in == nil { + return nil + } + out := new(ComputeResource) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ContainerView) DeepCopyInto(out *ContainerView) { *out = *in @@ -449,6 +467,20 @@ func (in *GenericResourceSpec) DeepCopyInto(out *GenericResourceSpec) { (*out)[key] = outVal } } + if in.Pods != nil { + in, out := &in.Pods, &out.Pods + *out = make([]ComputeResource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Storage != nil { + in, out := &in.Storage, &out.Storage + *out = make([]StorageResource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } out.Status = in.Status return } @@ -845,3 +877,21 @@ func (in *Service) DeepCopy() *Service { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *StorageResource) DeepCopyInto(out *StorageResource) { + *out = *in + in.CreationTimestamp.DeepCopyInto(&out.CreationTimestamp) + in.Resources.DeepCopyInto(&out.Resources) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageResource. +func (in *StorageResource) DeepCopy() *StorageResource { + if in == nil { + return nil + } + out := new(StorageResource) + in.DeepCopyInto(out) + return out +} diff --git a/crds/core.k8s.appscode.com_genericresources.yaml b/crds/core.k8s.appscode.com_genericresources.yaml index 66dc2cb4f..99e793948 100644 --- a/crds/core.k8s.appscode.com_genericresources.yaml +++ b/crds/core.k8s.appscode.com_genericresources.yaml @@ -144,6 +144,68 @@ spec: type: string name: type: string + pods: + items: + properties: + creationTimestamp: + format: date-time + type: string + name: + type: string + resource: + description: ResourceRequirements describes the compute resource + requirements. + properties: + claims: + description: "Claims lists the names of resources, defined + in spec.resourceClaims, that are used by this container. + \n This is an alpha field and requires enabling the DynamicResourceAllocation + feature gate. \n This field is immutable. It can only + be set for containers." + items: + description: ResourceClaim references one entry in PodSpec.ResourceClaims. + properties: + name: + description: Name must match the name of one entry + in pod.spec.resourceClaims of the Pod where this + field is used. It makes that resource available + inside a container. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Limits describes the maximum amount of compute + resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Requests describes the minimum amount of compute + resources required. If Requests is omitted for a container, + it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests + cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + required: + - name + type: object + type: array replicas: format: int64 type: integer @@ -185,6 +247,46 @@ spec: description: Status type: string type: object + storage: + items: + properties: + creationTimestamp: + format: date-time + type: string + name: + type: string + resources: + description: VolumeResourceRequirements describes the storage + resource requirements for a volume. + properties: + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Limits describes the maximum amount of compute + resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Requests describes the minimum amount of compute + resources required. If Requests is omitted for a container, + it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests + cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + required: + - name + type: object + type: array totalResource: description: ResourceRequirements describes the compute resource requirements. properties: