From af96b5b6f62abc287d217e417b2c9544c333dc51 Mon Sep 17 00:00:00 2001 From: Guilherme Cassolato Date: Mon, 4 Sep 2023 15:48:24 +0200 Subject: [PATCH] fix: set status field hostReady in the conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This field is required and therefore should be set as the Kube API server would – i.e. not as nil, but with an empty array when it has no elements. --- api/v1beta2/auth_config_conversion.go | 14 +++------ api/v1beta2/auth_config_conversion_test.go | 34 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/api/v1beta2/auth_config_conversion.go b/api/v1beta2/auth_config_conversion.go index e353a9ec..32e19ac6 100644 --- a/api/v1beta2/auth_config_conversion.go +++ b/api/v1beta2/auth_config_conversion.go @@ -1010,11 +1010,8 @@ func convertStatusFrom(src v1beta1.AuthConfigStatus) AuthConfigStatus { } func convertStatusSummaryTo(src AuthConfigStatusSummary) v1beta1.Summary { - var hostsReady []string - if len(src.HostsReady) > 0 { - hostsReady = make([]string, len(src.HostsReady)) - copy(hostsReady, src.HostsReady) - } + hostsReady := make([]string, len(src.HostsReady)) + copy(hostsReady, src.HostsReady) return v1beta1.Summary{ Ready: src.Ready, @@ -1029,11 +1026,8 @@ func convertStatusSummaryTo(src AuthConfigStatusSummary) v1beta1.Summary { } func convertStatusSummaryFrom(src v1beta1.Summary) AuthConfigStatusSummary { - var hostsReady []string - if len(src.HostsReady) > 0 { - hostsReady = make([]string, len(src.HostsReady)) - copy(hostsReady, src.HostsReady) - } + hostsReady := make([]string, len(src.HostsReady)) + copy(hostsReady, src.HostsReady) return AuthConfigStatusSummary{ Ready: src.Ready, diff --git a/api/v1beta2/auth_config_conversion_test.go b/api/v1beta2/auth_config_conversion_test.go index 6376a9af..359f5b77 100644 --- a/api/v1beta2/auth_config_conversion_test.go +++ b/api/v1beta2/auth_config_conversion_test.go @@ -59,7 +59,7 @@ func TestConvertFrom(t *testing.T) { func authConfig() *AuthConfig { authConfig := &AuthConfig{} - _ = json.Unmarshal([]byte(` + err := json.Unmarshal([]byte(` { "metadata": { "name": "auth-config" @@ -441,14 +441,29 @@ func authConfig() *AuthConfig { "value": "true" } ] + }, + "status": { + "summary": { + "ready": false, + "hostsReady": [], + "numHostsReady": "", + "numIdentitySources": 0, + "numMetadataSources": 0, + "numAuthorizationPolicies": 0, + "numResponseItems": 0, + "festivalWristbandEnabled": false + } } }`), &authConfig) + if err != nil { + panic(err) + } return authConfig } func hubAuthConfig() *v1beta1.AuthConfig { authConfig := &v1beta1.AuthConfig{} - _ = json.Unmarshal([]byte(` + err := json.Unmarshal([]byte(` { "metadata": { "name": "auth-config" @@ -963,7 +978,22 @@ func hubAuthConfig() *v1beta1.AuthConfig { "value": "true" } ] + }, + "status": { + "summary": { + "ready": false, + "hostsReady": [], + "numHostsReady": "", + "numIdentitySources": 0, + "numMetadataSources": 0, + "numAuthorizationPolicies": 0, + "numResponseItems": 0, + "festivalWristbandEnabled": false + } } }`), &authConfig) + if err != nil { + panic(err) + } return authConfig }