Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions templates/policies/application-policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ spec:
include:
- default
object-templates:
- complianceType: mustonlyhave
objectDefinition:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: openshift-gitops-cluster-admin-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: openshift-gitops-argocd-application-controller
namespace: openshift-gitops
- kind: ServiceAccount
name: openshift-gitops-argocd-server
namespace: openshift-gitops
- complianceType: mustonlyhave
objectDefinition:
apiVersion: argoproj.io/v1alpha1
Expand Down
93 changes: 76 additions & 17 deletions tests/application_policy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,65 @@ tests:
path: spec.clusterSelector.matchLabels.clusterGroup
value: group-two

# Test for openshift-gitops-cluster-admin-rolebinding CRB
- it: Should precreate the openshift-gitops-cluster-admin-rolebinding ClusterRoleBinding
values:
- ./clusterselector_values.yaml
set:
global:
multiSourceSupport: true
multiSourceRepoUrl: "https://charts.example.com"
multiSourceTargetRevision: "0.1.0"
asserts:
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.kind
value: ClusterRoleBinding
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.name
value: openshift-gitops-cluster-admin-rolebinding
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.roleRef.kind
value: ClusterRole
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.roleRef.name
value: cluster-admin
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].complianceType
value: mustonlyhave
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.subjects
content:
kind: ServiceAccount
name: openshift-gitops-argocd-application-controller
namespace: openshift-gitops
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
contains:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.subjects
content:
kind: ServiceAccount
name: openshift-gitops-argocd-server
namespace: openshift-gitops

# Tests for clusterGroupGitRepoUrl and clusterGroupChartGitRevision
- it: Should use chart clustergroup when clusterGroupGitRepoUrl is not set
values:
Expand All @@ -101,25 +160,25 @@ tests:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].chart
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].chart
value: clustergroup
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].repoURL
value: "https://charts.example.com"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].targetRevision
value: "0.1.0"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
isNull:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].path

- it: Should use path when clusterGroupGitRepoUrl is set
values:
Expand All @@ -138,25 +197,25 @@ tests:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].path
value: "."
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].repoURL
value: "https://github.com/example/clustergroup-chart"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].targetRevision
value: "feature-branch"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
isNull:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].chart
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].chart

- it: Should use clusterGroupGitRepoUrl with fallback to multiSourceTargetRevision when only clusterGroupGitRepoUrl is set
values:
Expand All @@ -174,19 +233,19 @@ tests:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].path
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].path
value: "."
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].repoURL
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].repoURL
value: "https://github.com/example/clustergroup-chart"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].targetRevision
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].targetRevision
value: "0.1.0"

- it: should render a spoke app of apps with the correct helm parameters (no deletePattern set)
Expand All @@ -208,19 +267,19 @@ tests:
path: metadata.name
value: group-one-clustergroup-policy
lengthEqual:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters
count: 20 # 17 (in the helper) +3 (1 override, and 1 clusterGroup.name)
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].name
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters[16].name
value: "global.deletePattern"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].value
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters[16].value
value: null

- it: should render a spoke app of apps with the correct helm parameters (if deletePattern set to DeleteSpokeChildApps)
Expand All @@ -243,19 +302,19 @@ tests:
path: metadata.name
value: group-one-clustergroup-policy
lengthEqual:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters
count: 20 # 17 (in the helper) +3 (1 override, and 1 clusterGroup.name)
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].name
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters[16].name
value: "global.deletePattern"
- documentSelector:
path: metadata.name
value: group-one-clustergroup-policy
equal:
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.sources[1].helm.parameters[16].value
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters[16].value
value: "DeleteChildApps"

- it: should not render a spoke app of apps (if deletePattern set to DeleteSpoke)
Expand Down
Loading