From 5f91ca22a33e3d2a68131682f349d344d421ac6d Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Thu, 7 Nov 2024 16:18:58 +0100 Subject: [PATCH 1/2] Introduce ConsumedCapacity into the SpaceProvisionerConfig status that is meant to mirror the relevant information from the ToolchainStatus for easier inspection of the cluster conditions. --- api/v1alpha1/docs/apiref.adoc | 29 +++++++++++++++++++- api/v1alpha1/spaceprovisionerconfig_types.go | 29 +++++++++++++++++--- api/v1alpha1/zz_generated.deepcopy.go | 27 ++++++++++++++++++ api/v1alpha1/zz_generated.openapi.go | 10 +++++-- 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/api/v1alpha1/docs/apiref.adoc b/api/v1alpha1/docs/apiref.adoc index 9912b345..42ef2ea0 100644 --- a/api/v1alpha1/docs/apiref.adoc +++ b/api/v1alpha1/docs/apiref.adoc @@ -471,6 +471,29 @@ Defines all parameters concerned with the console |=== +[id="{anchor_prefix}-github-com-codeready-toolchain-api-api-v1alpha1-consumedcapacity"] +==== ConsumedCapacity + + + +ConsumedCapacity describes the capacity of the cluster consumed by the spaces +currently provisioned to it. + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-codeready-toolchain-api-api-v1alpha1-spaceprovisionerconfigstatus[$$SpaceProvisionerConfigStatus$$] +**** + +[cols="20a,50a,15a,15a", options="header"] +|=== +| Field | Description | Default | Validation +| *`memoryUsagePercentPerNode`* __object (keys:string, values:integer)__ | MemoryUsagePercentPerNodeRole is the percent of the memory used per node role (eg. worker, master) + | | +| *`spaceCount`* __integer__ | SpaceCount is the number of spaces currently deployed to the cluster + | | +|=== + + [id="{anchor_prefix}-github-com-codeready-toolchain-api-api-v1alpha1-deactivationconfig"] ==== DeactivationConfig @@ -2861,8 +2884,12 @@ the space scheduling decisions. + | | [cols="20a,50a,15a,15a", options="header"] |=== | Field | Description | Default | Validation +| *`consumedCapacity`* __xref:{anchor_prefix}-github-com-codeready-toolchain-api-api-v1alpha1-consumedcapacity[$$ConsumedCapacity$$]__ | ConsumedCapacity reflects the runtime state of the cluster and the capacity it currently consumes. + +Nil if the consumed capacity is not known + | | | *`conditions`* __xref:{anchor_prefix}-github-com-codeready-toolchain-api-api-v1alpha1-condition[$$Condition$$] array__ | Conditions describes the state of the configuration (its validity). + -The only known condition type is "Ready". + | | +The only known condition type is "Ready". The SpaceProvisionerConfig is ready when the following is true: + +* the referenced ToolchainCluster object exists and is itself ready + +* the consumed capacity doesn't breach the thresholds defined in the spec + | | |=== diff --git a/api/v1alpha1/spaceprovisionerconfig_types.go b/api/v1alpha1/spaceprovisionerconfig_types.go index 52231d7b..f1b83881 100644 --- a/api/v1alpha1/spaceprovisionerconfig_types.go +++ b/api/v1alpha1/spaceprovisionerconfig_types.go @@ -3,9 +3,12 @@ package v1alpha1 import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" const ( - SpaceProvisionerConfigToolchainClusterNotFoundReason = "ToolchainClusterNotFound" - SpaceProvisionerConfigToolchainClusterNotReadyReason = "ToolchainClusterNotReady" - SpaceProvisionerConfigValidReason = "AllChecksPassed" + SpaceProvisionerConfigToolchainClusterNotFoundReason = "ToolchainClusterNotFound" + SpaceProvisionerConfigToolchainClusterNotReadyReason = "ToolchainClusterNotReady" + SpaceProvisionerConfigInsufficientCapacityReason = "InsufficientCapacity" + SpaceProvisionerConfigFailedToDetermineCapacityReason = "FailedToDetermineCapacity" + SpaceProvisionerConfigValidReason = "AllChecksPassed" + SpaceProvisionerConfigDisabledReason = "Disabled" ) // +k8s:openapi-gen=true @@ -50,10 +53,28 @@ type SpaceProvisionerCapacityThresholds struct { MaxMemoryUtilizationPercent uint `json:"maxMemoryUtilizationPercent,omitempty"` } +// ConsumedCapacity describes the capacity of the cluster consumed by the spaces +// currently provisioned to it. +type ConsumedCapacity struct { + // MemoryUsagePercentPerNodeRole is the percent of the memory used per node role (eg. worker, master) + MemoryUsagePercentPerNodeRole map[string]int `json:"memoryUsagePercentPerNode"` + + // SpaceCount is the number of spaces currently deployed to the cluster + SpaceCount int `json:"spaceCount"` +} + // +k8s:openapi-gen=true type SpaceProvisionerConfigStatus struct { + // ConsumedCapacity reflects the runtime state of the cluster and the capacity it currently consumes. + // Nil if the consumed capacity is not known + // +optional + ConsumedCapacity *ConsumedCapacity `json:"consumedCapacity,omitempty"` + // Conditions describes the state of the configuration (its validity). - // The only known condition type is "Ready". + // The only known condition type is "Ready". The SpaceProvisionerConfig is ready when the following is true: + // * the referenced ToolchainCluster object exists and is itself ready + // * the consumed capacity doesn't breach the thresholds defined in the spec + // // +optional // +patchMergeKey=type // +patchStrategy=merge diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 3ebacf6e..02a33a55 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -396,6 +396,28 @@ func (in *ConsoleConfig) DeepCopy() *ConsoleConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConsumedCapacity) DeepCopyInto(out *ConsumedCapacity) { + *out = *in + if in.MemoryUsagePercentPerNodeRole != nil { + in, out := &in.MemoryUsagePercentPerNodeRole, &out.MemoryUsagePercentPerNodeRole + *out = make(map[string]int, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConsumedCapacity. +func (in *ConsumedCapacity) DeepCopy() *ConsumedCapacity { + if in == nil { + return nil + } + out := new(ConsumedCapacity) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DeactivationConfig) DeepCopyInto(out *DeactivationConfig) { *out = *in @@ -2816,6 +2838,11 @@ func (in *SpaceProvisionerConfigSpec) DeepCopy() *SpaceProvisionerConfigSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SpaceProvisionerConfigStatus) DeepCopyInto(out *SpaceProvisionerConfigStatus) { *out = *in + if in.ConsumedCapacity != nil { + in, out := &in.ConsumedCapacity, &out.ConsumedCapacity + *out = new(ConsumedCapacity) + (*in).DeepCopyInto(*out) + } if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make([]Condition, len(*in)) diff --git a/api/v1alpha1/zz_generated.openapi.go b/api/v1alpha1/zz_generated.openapi.go index 50da023e..36328e21 100644 --- a/api/v1alpha1/zz_generated.openapi.go +++ b/api/v1alpha1/zz_generated.openapi.go @@ -4003,6 +4003,12 @@ func schema_codeready_toolchain_api_api_v1alpha1_SpaceProvisionerConfigStatus(re SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ + "consumedCapacity": { + SchemaProps: spec.SchemaProps{ + Description: "ConsumedCapacity reflects the runtime state of the cluster and the capacity it currently consumes. Nil if the consumed capacity is not known", + Ref: ref("github.com/codeready-toolchain/api/api/v1alpha1.ConsumedCapacity"), + }, + }, "conditions": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -4015,7 +4021,7 @@ func schema_codeready_toolchain_api_api_v1alpha1_SpaceProvisionerConfigStatus(re }, }, SchemaProps: spec.SchemaProps{ - Description: "Conditions describes the state of the configuration (its validity). The only known condition type is \"Ready\".", + Description: "Conditions describes the state of the configuration (its validity). The only known condition type is \"Ready\". The SpaceProvisionerConfig is ready when the following is true:\n * the referenced ToolchainCluster object exists and is itself ready\n * the consumed capacity doesn't breach the thresholds defined in the spec", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ @@ -4031,7 +4037,7 @@ func schema_codeready_toolchain_api_api_v1alpha1_SpaceProvisionerConfigStatus(re }, }, Dependencies: []string{ - "github.com/codeready-toolchain/api/api/v1alpha1.Condition"}, + "github.com/codeready-toolchain/api/api/v1alpha1.Condition", "github.com/codeready-toolchain/api/api/v1alpha1.ConsumedCapacity"}, } } From 27beb56ce156c4c811d0f5bb99d9594e3ac1375d Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Fri, 15 Nov 2024 13:16:09 +0100 Subject: [PATCH 2/2] fix the typo in the json field name. --- api/v1alpha1/docs/apiref.adoc | 2 +- api/v1alpha1/spaceprovisionerconfig_types.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/docs/apiref.adoc b/api/v1alpha1/docs/apiref.adoc index 42ef2ea0..d1cbcb90 100644 --- a/api/v1alpha1/docs/apiref.adoc +++ b/api/v1alpha1/docs/apiref.adoc @@ -489,7 +489,7 @@ currently provisioned to it. [cols="20a,50a,15a,15a", options="header"] |=== | Field | Description | Default | Validation -| *`memoryUsagePercentPerNode`* __object (keys:string, values:integer)__ | MemoryUsagePercentPerNodeRole is the percent of the memory used per node role (eg. worker, master) + | | +| *`memoryUsagePercentPerNodeRole`* __object (keys:string, values:integer)__ | MemoryUsagePercentPerNodeRole is the percent of the memory used per node role (eg. worker, master) + | | | *`spaceCount`* __integer__ | SpaceCount is the number of spaces currently deployed to the cluster + | | |=== diff --git a/api/v1alpha1/spaceprovisionerconfig_types.go b/api/v1alpha1/spaceprovisionerconfig_types.go index f1b83881..5963ef4e 100644 --- a/api/v1alpha1/spaceprovisionerconfig_types.go +++ b/api/v1alpha1/spaceprovisionerconfig_types.go @@ -57,7 +57,8 @@ type SpaceProvisionerCapacityThresholds struct { // currently provisioned to it. type ConsumedCapacity struct { // MemoryUsagePercentPerNodeRole is the percent of the memory used per node role (eg. worker, master) - MemoryUsagePercentPerNodeRole map[string]int `json:"memoryUsagePercentPerNode"` + // +maptype: atomic + MemoryUsagePercentPerNodeRole map[string]int `json:"memoryUsagePercentPerNodeRole"` // SpaceCount is the number of spaces currently deployed to the cluster SpaceCount int `json:"spaceCount"`