From f6581d52dc80daf64a633d1bbccab92ed8ff4562 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 19 Nov 2024 10:42:46 +0100 Subject: [PATCH] Introduce ConsumedCapacity into the SpaceProvisionerConfig status (#450) * Introduce ConsumedCapacity into the SpaceProvisionerConfig status that is meant to mirror the relevant information from the ToolchainStatus for easier inspection of the cluster conditions. * fix the typo in the json field name. --- api/v1alpha1/docs/apiref.adoc | 29 ++++++++++++++++++- api/v1alpha1/spaceprovisionerconfig_types.go | 30 +++++++++++++++++--- api/v1alpha1/zz_generated.deepcopy.go | 27 ++++++++++++++++++ api/v1alpha1/zz_generated.openapi.go | 10 +++++-- 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/api/v1alpha1/docs/apiref.adoc b/api/v1alpha1/docs/apiref.adoc index a0f295dd..b47eeb1b 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 +| *`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 + | | +|=== + + [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..5963ef4e 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,29 @@ 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) + // +maptype: atomic + MemoryUsagePercentPerNodeRole map[string]int `json:"memoryUsagePercentPerNodeRole"` + + // 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"}, } }