-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
operator: Add defaulting webhook for Enterprise fields
- Update Console validating webhook to mutating webhook - Refactor required keys used for validating/mutating to vars
- Loading branch information
Showing
6 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Package redpanda defines Webhooks for redpanda API group | ||
package redpanda | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
redpandav1alpha1 "github.com/redpanda-data/redpanda/src/go/k8s/apis/redpanda/v1alpha1" | ||
consolepkg "github.com/redpanda-data/redpanda/src/go/k8s/pkg/console" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var ( | ||
// ErrEnterpriseRBACDataKeyNotFound error when "rbac.yaml" not found in RBAC ref | ||
ErrEnterpriseRBACDataKeyNotFound = fmt.Errorf("must contain key '%s'", consolepkg.EnterpriseRBACDataKey) | ||
|
||
// ErrEnterpriseGoogleSADataKeyNotFound error when "sa.json" not found in Google SA ref | ||
ErrEnterpriseGoogleSADataKeyNotFound = fmt.Errorf("must contain key '%s'", consolepkg.EnterpriseGoogleSADataKey) | ||
) | ||
|
||
// ValidateEnterpriseRBAC validates the referenced RBAC ConfigMap | ||
func ValidateEnterpriseRBAC(ctx context.Context, cl client.Client, console *redpandav1alpha1.Console) error { | ||
if enterprise := console.Spec.Enterprise; enterprise != nil { | ||
configmap := &corev1.ConfigMap{} | ||
if err := cl.Get(ctx, client.ObjectKey{Namespace: console.GetNamespace(), Name: enterprise.RBAC.RoleBindingsRef.Name}, configmap); err != nil { | ||
return err | ||
} | ||
if _, ok := configmap.Data[consolepkg.EnterpriseRBACDataKey]; !ok { | ||
return ErrEnterpriseRBACDataKeyNotFound | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// ValidateEnterpriseGoogleSA validates the referenced Google SA ConfigMap | ||
func ValidateEnterpriseGoogleSA(ctx context.Context, cl client.Client, console *redpandav1alpha1.Console) error { | ||
if login := console.Spec.Login; login != nil && login.Google != nil && login.Google.Directory != nil { | ||
configmap := &corev1.ConfigMap{} | ||
if err := cl.Get(ctx, client.ObjectKey{Namespace: console.GetNamespace(), Name: login.Google.Directory.ServiceAccountRef.Name}, configmap); err != nil { | ||
return err | ||
} | ||
if _, ok := configmap.Data[consolepkg.EnterpriseGoogleSADataKey]; !ok { | ||
return ErrEnterpriseGoogleSADataKeyNotFound | ||
} | ||
} | ||
return nil | ||
} |