From 1e3b48c153e7e21d8ef93449fc6993b291c42778 Mon Sep 17 00:00:00 2001 From: Allan Reid Date: Sun, 8 Jan 2023 00:25:46 -0800 Subject: [PATCH] Add RuntimeClassName as parameter to Tenant creation Increase test coverage of tenant code with RuntimeClassName --- models/pool.go | 3 +++ operatorapi/embedded_spec.go | 6 ++++++ operatorapi/tenants.go | 25 +++++++++++++++++-------- operatorapi/tenants_test.go | 24 ++++++++++++++++++------ swagger-operator.yml | 4 +++- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/models/pool.go b/models/pool.go index ae6e39b566..3f35e076b6 100644 --- a/models/pool.go +++ b/models/pool.go @@ -48,6 +48,9 @@ type Pool struct { // resources Resources *PoolResources `json:"resources,omitempty"` + // runtime class name + RuntimeClassName string `json:"runtimeClassName,omitempty"` + // security context SecurityContext *SecurityContext `json:"securityContext,omitempty"` diff --git a/operatorapi/embedded_spec.go b/operatorapi/embedded_spec.go index 5bae518c44..cbc436391a 100644 --- a/operatorapi/embedded_spec.go +++ b/operatorapi/embedded_spec.go @@ -4043,6 +4043,9 @@ func init() { "resources": { "$ref": "#/definitions/poolResources" }, + "runtimeClassName": { + "type": "string" + }, "securityContext": { "type": "object", "$ref": "#/definitions/securityContext" @@ -9976,6 +9979,9 @@ func init() { "resources": { "$ref": "#/definitions/poolResources" }, + "runtimeClassName": { + "type": "string" + }, "securityContext": { "type": "object", "$ref": "#/definitions/securityContext" diff --git a/operatorapi/tenants.go b/operatorapi/tenants.go index 6017c347dd..d98451075b 100644 --- a/operatorapi/tenants.go +++ b/operatorapi/tenants.go @@ -2270,9 +2270,10 @@ func parseTenantPoolRequest(poolParams *models.Pool) (*miniov2.Pool, error) { Requests: resourcesRequests, Limits: resourcesLimits, }, - NodeSelector: poolParams.NodeSelector, - Affinity: affinity, - Tolerations: tolerations, + NodeSelector: poolParams.NodeSelector, + Affinity: affinity, + Tolerations: tolerations, + RuntimeClassName: &poolParams.RuntimeClassName, } // if security context for Tenant is present, configure it. if poolParams.SecurityContext != nil { @@ -2493,6 +2494,13 @@ func parseTenantPool(pool *miniov2.Pool) *models.Pool { } } + runtimeClassNameValue := "" + runtimeClassName := &runtimeClassNameValue + + if pool.RuntimeClassName != nil { + runtimeClassName = pool.RuntimeClassName + } + poolModel := &models.Pool{ Name: pool.Name, Servers: swag.Int64(int64(pool.Servers)), @@ -2501,11 +2509,12 @@ func parseTenantPool(pool *miniov2.Pool) *models.Pool { Size: size, StorageClassName: storageClassName, }, - NodeSelector: pool.NodeSelector, - Resources: resources, - Affinity: affinity, - Tolerations: tolerations, - SecurityContext: &securityContext, + NodeSelector: pool.NodeSelector, + Resources: resources, + Affinity: affinity, + Tolerations: tolerations, + SecurityContext: &securityContext, + RuntimeClassName: *runtimeClassName, } return poolModel } diff --git a/operatorapi/tenants_test.go b/operatorapi/tenants_test.go index 851c1ce2c1..0d17b85e54 100644 --- a/operatorapi/tenants_test.go +++ b/operatorapi/tenants_test.go @@ -383,7 +383,7 @@ export MINIO_SECRET_KEY=minio123 } } -func NoTestTenantInfo(t *testing.T) { +func Test_TenantInfo(t *testing.T) { testTimeStamp := metav1.Now() type args struct { minioTenant *miniov2.Tenant @@ -418,6 +418,7 @@ func NoTestTenantInfo(t *testing.T) { StorageClassName: swag.String("standard"), }, }, + RuntimeClassName: swag.String(""), }, }, @@ -435,7 +436,12 @@ func NoTestTenantInfo(t *testing.T) { CurrentState: "ready", Pools: []*models.Pool{ { - Name: "pool1", + Name: "pool1", + SecurityContext: &models.SecurityContext{ + RunAsGroup: nil, + RunAsNonRoot: nil, + RunAsUser: nil, + }, Servers: swag.Int64(int64(2)), VolumesPerServer: swag.Int32(4), VolumeConfiguration: &models.PoolVolumeConfiguration{ @@ -483,6 +489,7 @@ func NoTestTenantInfo(t *testing.T) { StorageClassName: swag.String("standard"), }, }, + RuntimeClassName: swag.String(""), }, }, Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z", @@ -500,7 +507,12 @@ func NoTestTenantInfo(t *testing.T) { CurrentState: "ready", Pools: []*models.Pool{ { - Name: "pool1", + Name: "pool1", + SecurityContext: &models.SecurityContext{ + RunAsGroup: nil, + RunAsNonRoot: nil, + RunAsUser: nil, + }, Servers: swag.Int64(int64(2)), VolumesPerServer: swag.Int32(4), VolumeConfiguration: &models.PoolVolumeConfiguration{ @@ -1025,7 +1037,7 @@ func Test_UpdateTenantAction(t *testing.T) { }, params: operator_api.UpdateTenantParams{ Body: &models.UpdateTenantRequest{ - Image: "minio/minio:RELEASE.2020-06-03T22-13-49Z", + Image: "minio/minio:RELEASE.2023-01-06T18-11-18Z", }, }, }, @@ -1050,7 +1062,7 @@ func Test_UpdateTenantAction(t *testing.T) { }, params: operator_api.UpdateTenantParams{ Body: &models.UpdateTenantRequest{ - Image: "minio/minio:RELEASE.2020-06-03T22-13-49Z", + Image: "minio/minio:RELEASE.2023-01-06T18-11-18Z", }, }, }, @@ -1076,7 +1088,7 @@ func Test_UpdateTenantAction(t *testing.T) { params: operator_api.UpdateTenantParams{ Tenant: "minio-tenant", Body: &models.UpdateTenantRequest{ - Image: "minio/minio:RELEASE.2020-06-03T22-13-49Z", + Image: "minio/minio:RELEASE.2023-01-06T18-11-18Z", }, }, }, diff --git a/swagger-operator.yml b/swagger-operator.yml index 902ca97552..07e13e723a 100644 --- a/swagger-operator.yml +++ b/swagger-operator.yml @@ -2610,6 +2610,8 @@ definitions: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" affinity: $ref: "#/definitions/poolAffinity" + runtimeClassName: + type: string tolerations: $ref: "#/definitions/poolTolerations" securityContext: @@ -3750,4 +3752,4 @@ definitions: redirect: type: string displayName: - type: string + type: string \ No newline at end of file