-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from sabre1041/installplan-approval
Manual approval strategy
- Loading branch information
Showing
5 changed files
with
143 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
annotations: | ||
config.example.com/managed-by: gitops | ||
config.example.com/scm-url: git@github.com:redhat-cop/declarative-openshift.git | ||
labels: | ||
config.example.com/name: simple-bootstrap | ||
config.example.com/component: rbac | ||
name: installplan-approver-job | ||
namespace: resource-locker-operator | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
annotations: | ||
config.example.com/managed-by: gitops | ||
config.example.com/scm-url: git@github.com:redhat-cop/declarative-openshift.git | ||
labels: | ||
config.example.com/name: simple-bootstrap | ||
config.example.com/component: rbac | ||
name: installplan-approver | ||
namespace: resource-locker-operator | ||
rules: | ||
- apiGroups: | ||
- operators.coreos.com | ||
resources: | ||
- installplans | ||
- subscriptions | ||
verbs: | ||
- get | ||
- list | ||
- patch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
annotations: | ||
config.example.com/managed-by: gitops | ||
config.example.com/scm-url: git@github.com:redhat-cop/declarative-openshift.git | ||
labels: | ||
config.example.com/name: simple-bootstrap | ||
config.example.com/component: rbac | ||
name: installplan-approvers | ||
namespace: resource-locker-operator | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: installplan-approver | ||
subjects: | ||
- kind: ServiceAccount | ||
name: installplan-approver-job |
Empty file.
53 changes: 53 additions & 0 deletions
53
simple-bootstrap/3-operator-configs/installplan-approver-job.yaml
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,53 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
annotations: | ||
config.example.com/managed-by: gitops | ||
config.example.com/scm-url: git@github.com:redhat-cop/declarative-openshift.git | ||
labels: | ||
config.example.com/name: simple-bootstrap | ||
config.example.com/component: configs | ||
name: installplan-approver | ||
namespace: resource-locker-operator | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- image: registry.redhat.io/openshift4/ose-cli:v4.4 | ||
command: | ||
- /bin/bash | ||
- -c | ||
- | | ||
export HOME=/tmp/approver | ||
echo "Approving operator InstallPlans. Waiting a few seconds to make sure the InstallPlan gets created first." | ||
sleep 10 | ||
for subscription in `oc get subscription -o name` | ||
do | ||
desiredcsv=$(oc get $subscription -o jsonpath='{ .spec.startingCSV }') | ||
until [ "$(oc get installplan --template="{{ range \$item := .items }}{{ range \$item.spec.clusterServiceVersionNames }}{{ if eq . \"$desiredcsv\"}}{{ printf \"%s\n\" \$item.metadata.name }}{{end}}{{end}}{{end}}")" != "" ]; do sleep 2; done | ||
installplans=$(oc get installplan --template="{{ range \$item := .items }}{{ range \$item.spec.clusterServiceVersionNames }}{{ if eq . \"$desiredcsv\"}}{{ printf \"%s\n\" \$item.metadata.name }}{{end}}{{end}}{{end}}") | ||
for installplan in $installplans | ||
do | ||
if [ "`oc get installplan $installplan -o jsonpath="{.spec.approved}"`" == "false" ]; then | ||
echo "Approving Subscription $subscription with install plan $installplan" | ||
oc patch installplan $installplan --type=json -p='[{"op":"replace","path": "/spec/approved", "value": true}]' | ||
else | ||
echo "Install Plan '$installplan' already approved" | ||
fi | ||
done | ||
done | ||
imagePullPolicy: Always | ||
name: installplan-approver | ||
dnsPolicy: ClusterFirst | ||
restartPolicy: OnFailure | ||
serviceAccount: installplan-approver-job | ||
serviceAccountName: installplan-approver-job | ||
terminationGracePeriodSeconds: 30 |