From ed1c49e79b166def43135121a19ab3d8e7fe6a76 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Mon, 13 Jan 2025 14:57:15 +0600 Subject: [PATCH] Report pod and storage resource via generic resource (#529) Signed-off-by: Tamal Saha --- apis/core/v1alpha1/generic_resource_types.go | 29 ++- apis/core/v1alpha1/openapi_generated.go | 151 +++++++++++++- apis/core/v1alpha1/zz_generated.deepcopy.go | 85 ++++++++ ...ore.k8s.appscode.com_genericresources.yaml | 186 ++++++++++++++++++ 4 files changed, 449 insertions(+), 2 deletions(-) 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..cf050388f 100644 --- a/apis/core/v1alpha1/openapi_generated.go +++ b/apis/core/v1alpha1/openapi_generated.go @@ -358,6 +358,8 @@ 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.ContainerResource": schema_resource_metadata_apis_core_v1alpha1_ContainerResource(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 +386,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 +18872,93 @@ 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"), + }, + }, + "containers": { + 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.ContainerResource"), + }, + }, + }, + }, + }, + "initContainers": { + 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.ContainerResource"), + }, + }, + }, + }, + }, + }, + Required: []string{"name"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.Time", "kmodules.xyz/resource-metadata/apis/core/v1alpha1.ContainerResource"}, + } +} + +func schema_resource_metadata_apis_core_v1alpha1_ContainerResource(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: "", + }, + }, + "resource": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/api/core/v1.ResourceRequirements"), + }, + }, + "restartPolicy": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"name"}, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.ResourceRequirements"}, + } +} + func schema_resource_metadata_apis_core_v1alpha1_ContainerView(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -19738,6 +19828,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 +19865,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 +20481,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..a081865a7 100644 --- a/apis/core/v1alpha1/zz_generated.deepcopy.go +++ b/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -34,6 +34,59 @@ 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) + if in.Containers != nil { + in, out := &in.Containers, &out.Containers + *out = make([]ContainerResource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.InitContainers != nil { + in, out := &in.InitContainers, &out.InitContainers + *out = make([]ContainerResource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + 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 *ContainerResource) DeepCopyInto(out *ContainerResource) { + *out = *in + in.Resource.DeepCopyInto(&out.Resource) + if in.RestartPolicy != nil { + in, out := &in.RestartPolicy, &out.RestartPolicy + *out = new(v1.ContainerRestartPolicy) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerResource. +func (in *ContainerResource) DeepCopy() *ContainerResource { + if in == nil { + return nil + } + out := new(ContainerResource) + 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 +502,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 +912,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..d2b181971 100644 --- a/crds/core.k8s.appscode.com_genericresources.yaml +++ b/crds/core.k8s.appscode.com_genericresources.yaml @@ -144,6 +144,152 @@ spec: type: string name: type: string + pods: + items: + properties: + containers: + items: + properties: + 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 + restartPolicy: + description: ContainerRestartPolicy is the restart policy + for a single container. This may only be set for init + containers and only allowed value is "Always". + type: string + required: + - name + type: object + type: array + creationTimestamp: + format: date-time + type: string + initContainers: + items: + properties: + 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 + restartPolicy: + description: ContainerRestartPolicy is the restart policy + for a single container. This may only be set for init + containers and only allowed value is "Always". + type: string + required: + - name + type: object + type: array + name: + type: string + required: + - name + type: object + type: array replicas: format: int64 type: integer @@ -185,6 +331,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: