Skip to content

Commit 5a275f6

Browse files
Add space to scope
1 parent dfa58d3 commit 5a275f6

File tree

7 files changed

+24
-3
lines changed

7 files changed

+24
-3
lines changed

config/crd/bases/agent.octopus.com_workloadserviceaccounts.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ spec:
154154
pattern: ^[\p{Ll}\p{N}]+(?:-[\p{L}\p{N}]+)*$
155155
type: string
156156
type: array
157+
spaces:
158+
items:
159+
pattern: ^[\p{Ll}\p{N}]+(?:-[\p{L}\p{N}]+)*$
160+
type: string
161+
type: array
157162
steps:
158163
items:
159164
pattern: ^[\p{Ll}\p{N}]+(?:-[\p{L}\p{N}]+)*$

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/octopusdeploy/octopus-permissions-controller
33
go 1.24.0
44

55
require (
6+
github.com/google/go-cmp v0.7.0
67
github.com/onsi/ginkgo/v2 v2.22.0
78
github.com/onsi/gomega v1.36.1
89
github.com/stretchr/testify v1.10.0
@@ -36,7 +37,6 @@ require (
3637
github.com/google/btree v1.1.3 // indirect
3738
github.com/google/cel-go v0.23.2 // indirect
3839
github.com/google/gnostic-models v0.6.9 // indirect
39-
github.com/google/go-cmp v0.7.0 // indirect
4040
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
4141
github.com/google/uuid v1.6.0 // indirect
4242
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect

hack/test-resource.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ spec:
1111
- Development
1212
steps:
1313
- "*"
14+
spaces:
15+
- "test-space"
1416
permissions:
1517
clusterRoles:
1618
- apiGroup: "rbac.authorization.k8s.io"

internal/controller/workloadserviceaccount_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func (r *WorkloadServiceAccountReconciler) Reconcile(ctx context.Context, req ct
6767
for _, step := range currentWSA.Spec.Scope.Steps {
6868
log.Info("WSA has step scope", "wsa", currentWSA.Name, "step", step)
6969
}
70+
for _, space := range currentWSA.Spec.Scope.Spaces {
71+
log.Info("WSA has space scope", "wsa", currentWSA.Name, "space", space)
72+
}
7073
}
7174

7275
log.Info("Successfully reconciled WorkloadServiceAccounts")

internal/webhook/v1beta1/workloadserviceaccount_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (v *WorkloadServiceAccountCustomValidator) ValidateCreate(_ context.Context
6767
workloadserviceaccountlog.Info("Validation for WorkloadServiceAccount upon creation", "name", workloadserviceaccount.GetName())
6868

6969
scope := workloadserviceaccount.Spec.Scope
70-
if len(scope.Projects)+len(scope.Environments)+len(scope.Tenants)+len(scope.Steps) == 0 {
71-
return nil, fmt.Errorf("at least one scope must be defined (projects, environments, tenants, or steps)")
70+
if len(scope.Projects)+len(scope.Environments)+len(scope.Tenants)+len(scope.Steps)+len(scope.Spaces) == 0 {
71+
return nil, fmt.Errorf("at least one scope must be defined (projects, environments, tenants, steps, or spaces)")
7272
}
7373

7474
return nil, nil

internal/webhook/v1beta1/workloadserviceaccount_webhook_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ var _ = Describe("WorkloadServiceAccount Webhook", func() {
5858
Expect(warnings).To(BeNil())
5959
})
6060

61+
It("Should allow creation with space scope", func() {
62+
By("setting up a WorkloadServiceAccount with space scope")
63+
obj.Spec.Scope.Spaces = []string{"production-space", "dev-space"}
64+
65+
By("validating the creation")
66+
warnings, err := validator.ValidateCreate(ctx, obj)
67+
Expect(err).NotTo(HaveOccurred())
68+
Expect(warnings).To(BeNil())
69+
})
70+
6171
It("Should deny creation if all scopes are missing", func() {
6272
By("setting up a WorkloadServiceAccount with no scopes")
6373
obj.Spec.Scope = agentoctopuscomv1beta1.WorkloadServiceAccountScope{}

test/e2e/test-wsa.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ spec:
66
scope:
77
projects: ["test-project"]
88
environments: ["test-env"]
9+
spaces: ["test-space"]
910
permissions:
1011
permissions:
1112
- apiGroups: [""]

0 commit comments

Comments
 (0)