Skip to content

Commit

Permalink
fix: avoid panic in operator-ca secret checks (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Sep 11, 2023
1 parent 2f9b7b6 commit ed2a2f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ func (c *Controller) syncHandler(key string) (Result, error) {
}

// check if operator-ca-tls has to be updated or re-created in the tenant namespace
operatorCATLSExists, err := c.checkOperatorCaForTenant(ctx, tenant)
operatorCATLSExists, err := c.checkOperatorCAForTenant(ctx, tenant)
if err != nil {
return WrapResult(Result{}, err)
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/controller/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func getOperatorCertFromSecret(secretData map[string][]byte, key string) ([]byte
}

// checkOperatorCaForTenant create or updates the operator-ca-tls secret for tenant if need it
func (c *Controller) checkOperatorCaForTenant(ctx context.Context, tenant *miniov2.Tenant) (operatorCATLSExists bool, err error) {
var certsData map[string][]byte
func (c *Controller) checkOperatorCAForTenant(ctx context.Context, tenant *miniov2.Tenant) (operatorCATLSExists bool, err error) {
certsData := make(map[string][]byte)

// get operator-ca-tls in minio-operator namespace
operatorCaSecret, err := c.kubeClientSet.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(ctx, OperatorCATLSSecretName, metav1.GetOptions{})
Expand All @@ -143,13 +143,10 @@ func (c *Controller) checkOperatorCaForTenant(ctx context.Context, tenant *minio
}

operatorPublicCert, err := getOperatorCertFromSecret(operatorCaSecret.Data, common.PublicCRT)
if err != nil {
// If no public.crt is present we error, other certs are optional
return false, err
if err == nil {
certsData[common.PublicCRT] = operatorPublicCert
}

certsData[common.PublicCRT] = operatorPublicCert

operatorTLSCert, err := getOperatorCertFromSecret(operatorCaSecret.Data, common.TLSCRT)
if err == nil {
certsData[common.TLSCRT] = operatorTLSCert
Expand All @@ -160,6 +157,10 @@ func (c *Controller) checkOperatorCaForTenant(ctx context.Context, tenant *minio
certsData[common.CACRT] = operatorCACert
}

if len(certsData) == 0 {
return false, fmt.Errorf("'%s' secret exists but is missing public.crt, tls.crt and ca.crt, please fix it manually", OperatorCATLSSecretName)
}

var tenantCaSecret *corev1.Secret

createTenantCASecret := func() error {
Expand Down

0 comments on commit ed2a2f7

Please sign in to comment.