Skip to content

Commit

Permalink
squash! feat: add expression support to workloadSelector (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakknutsen committed Aug 27, 2024
1 parent 0555672 commit a0bc161
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 4 additions & 5 deletions controllers/authzctrl/reconcile_authpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ func (r *Controller) reconcileAuthPolicy(ctx context.Context, target *unstructur
found := &istiosecurityv1beta1.AuthorizationPolicy{}
justCreated := false

err = r.Get(ctx, types.NamespacedName{
typeName := types.NamespacedName{
Name: desired.Name,
Namespace: desired.Namespace,
}, found)
if err != nil {
Namespace: desired.Namespace}
if errGet := r.Get(ctx, typeName, found); errGet != nil {
if k8serr.IsNotFound(err) {
errCreate := r.Create(ctx, desired)
if client.IgnoreAlreadyExists(errCreate) != nil {
Expand All @@ -42,7 +41,7 @@ func (r *Controller) reconcileAuthPolicy(ctx context.Context, target *unstructur

justCreated = true
} else {
return fmt.Errorf("unable to fetch AuthorizationPolicy: %w", err)
return fmt.Errorf("unable to fetch AuthorizationPolicy: %w", errGet)
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type ProtectedResource struct {
ObjectReference `json:"ref,omitempty"`
// WorkloadSelector defines labels used to identify and select the specific workload
// to which the authorization policy should be applied.
// All provided label selectors must be present on the Service to find a match.
//
// go expressions are handled in the selector key and value to set dynamic values from the current ObjectReference;
// e.g. "routing.opendatahub.io/{{.kind}}": "{{.metadata.name}}", // > "routing.opendatahub.io/Service": "MyService"
WorkloadSelector map[string]string `json:"workloadSelector,omitempty"`
// HostPaths defines paths in custom resource where hosts for this component are defined.
HostPaths []string `json:"hostPaths,omitempty"` // TODO(mvp): should we switch to annotations like in routing?
Expand Down

0 comments on commit a0bc161

Please sign in to comment.