From eaf5f0c1a2e0f3e89b392b53c292cb855ca52ef6 Mon Sep 17 00:00:00 2001 From: Pedro Juarez Date: Tue, 28 Nov 2023 10:55:39 -0800 Subject: [PATCH] remove pointer from `Users` field (#1892) Signed-off-by: pjuarezd --- api/tenant-add-handlers.go | 10 +++++----- kubectl-minio/cmd/resources/tenant.go | 2 +- pkg/apis/minio.min.io/v2/types.go | 2 +- pkg/apis/minio.min.io/v2/zz_generated.deepcopy.go | 10 ++-------- .../applyconfiguration/minio.min.io/v2/tenantspec.go | 7 ++----- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/api/tenant-add-handlers.go b/api/tenant-add-handlers.go index 719cfe10eff..5d12e0b50df 100644 --- a/api/tenant-add-handlers.go +++ b/api/tenant-add-handlers.go @@ -54,7 +54,7 @@ func createTenant(ctx context.Context, params operator_api.CreateTenantParams, c accessKey, secretKey := getTenantCredentials(tenantReq.AccessKey, tenantReq.SecretKey) tenantName := *tenantReq.Name - var users []*corev1.LocalObjectReference + var users []corev1.LocalObjectReference // delete secrets created if an errors occurred during tenant creation, defer func() { @@ -387,7 +387,7 @@ func deleteSecretsIfTenantCreationFails(ctx context.Context, mError *models.Erro } } -func setTenantActiveDirectoryConfig(ctx context.Context, clientSet K8sClientI, tenantReq *models.CreateTenantRequest, tenantConfigurationENV map[string]string, users []*corev1.LocalObjectReference) (map[string]string, []*corev1.LocalObjectReference, error) { +func setTenantActiveDirectoryConfig(ctx context.Context, clientSet K8sClientI, tenantReq *models.CreateTenantRequest, tenantConfigurationENV map[string]string, users []corev1.LocalObjectReference) (map[string]string, []corev1.LocalObjectReference, error) { imm := true serverAddress := *tenantReq.Idp.ActiveDirectory.URL tlsSkipVerify := tenantReq.Idp.ActiveDirectory.SkipTLSVerification @@ -427,7 +427,7 @@ func setTenantActiveDirectoryConfig(ctx context.Context, clientSet K8sClientI, t // Attach the list of LDAP user DNs that will be administrator for the Tenant for i, userDN := range tenantReq.Idp.ActiveDirectory.UserDNS { userSecretName := fmt.Sprintf("%s-user-%d", *tenantReq.Name, i) - users = append(users, &corev1.LocalObjectReference{Name: userSecretName}) + users = append(users, corev1.LocalObjectReference{Name: userSecretName}) userSecret := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -466,11 +466,11 @@ func setTenantOIDCConfig(tenantReq *models.CreateTenantRequest, tenantConfigurat return tenantConfigurationENV } -func setTenantBuiltInUsers(ctx context.Context, clientSet K8sClientI, tenantReq *models.CreateTenantRequest, users []*corev1.LocalObjectReference) ([]*corev1.LocalObjectReference, error) { +func setTenantBuiltInUsers(ctx context.Context, clientSet K8sClientI, tenantReq *models.CreateTenantRequest, users []corev1.LocalObjectReference) ([]corev1.LocalObjectReference, error) { imm := true for i := 0; i < len(tenantReq.Idp.Keys); i++ { userSecretName := fmt.Sprintf("%s-user-%d", *tenantReq.Name, i) - users = append(users, &corev1.LocalObjectReference{Name: userSecretName}) + users = append(users, corev1.LocalObjectReference{Name: userSecretName}) userSecret := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: userSecretName, diff --git a/kubectl-minio/cmd/resources/tenant.go b/kubectl-minio/cmd/resources/tenant.go index 69e3b81bcb7..0bce6b6c74e 100644 --- a/kubectl-minio/cmd/resources/tenant.go +++ b/kubectl-minio/cmd/resources/tenant.go @@ -133,7 +133,7 @@ func NewTenant(opts *TenantOptions, userSecret *v1.Secret) (*miniov2.Tenant, err Mountpath: helpers.MinIOMountPath, KES: tenantKESConfig(opts.Name, opts.KmsSecret, opts.KesImage), ImagePullSecret: v1.LocalObjectReference{Name: opts.ImagePullSecret}, - Users: []*v1.LocalObjectReference{ + Users: []v1.LocalObjectReference{ { Name: userSecret.Name, }, diff --git a/pkg/apis/minio.min.io/v2/types.go b/pkg/apis/minio.min.io/v2/types.go index e0bf5403b71..674a2e9dc6d 100644 --- a/pkg/apis/minio.min.io/v2/types.go +++ b/pkg/apis/minio.min.io/v2/types.go @@ -329,7 +329,7 @@ type TenantSpec struct { // // The Operator creates each user with the `consoleAdmin` policy by default. You can change the assigned policy after the Tenant starts. + // +optional - Users []*corev1.LocalObjectReference `json:"users,omitempty"` + Users []corev1.LocalObjectReference `json:"users,omitempty"` // *Optional* + // // Create buckets when creating a new tenant. Skip if bucket with given name already exists diff --git a/pkg/apis/minio.min.io/v2/zz_generated.deepcopy.go b/pkg/apis/minio.min.io/v2/zz_generated.deepcopy.go index b066579713b..69d775ac116 100644 --- a/pkg/apis/minio.min.io/v2/zz_generated.deepcopy.go +++ b/pkg/apis/minio.min.io/v2/zz_generated.deepcopy.go @@ -739,14 +739,8 @@ func (in *TenantSpec) DeepCopyInto(out *TenantSpec) { } if in.Users != nil { in, out := &in.Users, &out.Users - *out = make([]*v1.LocalObjectReference, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(v1.LocalObjectReference) - **out = **in - } - } + *out = make([]v1.LocalObjectReference, len(*in)) + copy(*out, *in) } if in.Buckets != nil { in, out := &in.Buckets, &out.Buckets diff --git a/pkg/client/applyconfiguration/minio.min.io/v2/tenantspec.go b/pkg/client/applyconfiguration/minio.min.io/v2/tenantspec.go index fbbbea96648..487e376ef46 100644 --- a/pkg/client/applyconfiguration/minio.min.io/v2/tenantspec.go +++ b/pkg/client/applyconfiguration/minio.min.io/v2/tenantspec.go @@ -53,7 +53,7 @@ type TenantSpecApplyConfiguration struct { SideCars *SideCarsApplyConfiguration `json:"sideCars,omitempty"` ExposeServices *ExposeServicesApplyConfiguration `json:"exposeServices,omitempty"` ServiceMetadata *ServiceMetadataApplyConfiguration `json:"serviceMetadata,omitempty"` - Users []*v1.LocalObjectReference `json:"users,omitempty"` + Users []v1.LocalObjectReference `json:"users,omitempty"` Buckets []BucketApplyConfiguration `json:"buckets,omitempty"` Logging *LoggingApplyConfiguration `json:"logging,omitempty"` Configuration *v1.LocalObjectReference `json:"configuration,omitempty"` @@ -301,11 +301,8 @@ func (b *TenantSpecApplyConfiguration) WithServiceMetadata(value *ServiceMetadat // WithUsers adds the given value to the Users field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Users field. -func (b *TenantSpecApplyConfiguration) WithUsers(values ...*v1.LocalObjectReference) *TenantSpecApplyConfiguration { +func (b *TenantSpecApplyConfiguration) WithUsers(values ...v1.LocalObjectReference) *TenantSpecApplyConfiguration { for i := range values { - if values[i] == nil { - panic("nil value passed to WithUsers") - } b.Users = append(b.Users, values[i]) } return b