Skip to content

Commit 250bf49

Browse files
committed
create label singleton lsr script
Signed-off-by: YuChen <[email protected]>
1 parent 5360f88 commit 250bf49

File tree

5 files changed

+226
-42
lines changed

5 files changed

+226
-42
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed Materials - Property of IBM
4+
# Copyright IBM Corporation 2023. All Rights Reserved
5+
# US Government Users Restricted Rights -
6+
# Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
7+
#
8+
# This is an internal component, bundled with an official IBM product.
9+
# Please refer to that particular license for additional information.
10+
11+
set -o errtrace
12+
set -o nounset
13+
14+
# ---------- Command arguments ----------
15+
OC=oc
16+
LSR_NAMESPACE="ibm-lsr"
17+
18+
# Catalog sources and namespace
19+
ENABLE_PRIVATE_CATALOG=0
20+
LSR_SOURCE="ibm-license-service-reporter-catalog"
21+
LSR_SOURCE_NS="openshift-marketplace"
22+
23+
# ---------- Command variables ----------
24+
25+
# script base directory
26+
BASE_DIR=$(cd $(dirname "$0")/$(dirname "$(readlink $0)") && pwd -P)
27+
28+
# ---------- Main functions ----------
29+
function main() {
30+
parse_arguments "$@"
31+
pre_req
32+
label_catalogsource
33+
label_ns_and_related
34+
label_subscription
35+
label_lsr
36+
success "Successfully labeled all the resources"
37+
}
38+
39+
function print_usage(){ #TODO update usage definition
40+
script_name=`basename ${0}`
41+
echo "Usage: ${script_name} [OPTIONS]"
42+
echo ""
43+
echo "Label License Service Reporter resources to prepare for Backup."
44+
echo "License Service Reporter namespace is always required."
45+
echo ""
46+
echo "Options:"
47+
echo " --oc string Optional. File path to oc CLI. Default uses oc in your PATH. Can also be set in env.properties."
48+
echo " --lsr-ns Optional. Specifying will enable labeling of the license service reporter operator. Permissions may need to be updated to include the namespace."
49+
echo " --enable-private-catalog Optional. Specifying will look for catalog sources in the operator namespace. If enabled, will look for license service reporter in its respective namespaces."
50+
echo " --lsr-catalog Optional. Specifying will look for the license service reporter catalog source name."
51+
echo " --lsr-catalog-ns Optional. Specifying will look for the license service reporter catalog source namespace."
52+
echo " -h, --help Print usage information"
53+
echo ""
54+
55+
}
56+
57+
function parse_arguments() {
58+
script_name=`basename ${0}`
59+
echo "All arguments passed into the ${script_name}: $@"
60+
echo ""
61+
62+
# process options
63+
while [[ "$@" != "" ]]; do
64+
case "$1" in
65+
--oc)
66+
shift
67+
OC=$1
68+
;;
69+
--lsr-ns )
70+
shift
71+
LSR_NAMESPACE=$1
72+
;;
73+
--enable-private-catalog)
74+
ENABLE_PRIVATE_CATALOG=1
75+
;;
76+
--lsr-catalog)
77+
shift
78+
LSR_SOURCE=$1
79+
;;
80+
--lsr-catalog-ns)
81+
shift
82+
LSR_SOURCE_NS=$1
83+
;;
84+
-h | --help)
85+
print_usage
86+
exit 1
87+
;;
88+
*)
89+
echo "Entered option $1 not supported. Run ./${script_name} -h for script usage info."
90+
;;
91+
esac
92+
shift
93+
done
94+
echo ""
95+
}
96+
97+
function pre_req(){
98+
99+
title "Start to validate the parameters passed into script... "
100+
# Checking oc command logged in
101+
user=$($OC whoami 2> /dev/null)
102+
if [ $? -ne 0 ]; then
103+
error "You must be logged into the OpenShift Cluster from the oc command line"
104+
else
105+
success "oc command logged in as ${user}"
106+
fi
107+
}
108+
109+
function label_catalogsource() {
110+
111+
title "Start to label the License Service Reporter catalog sources... "
112+
# Label the Private CatalogSources in provided namespaces
113+
if [ $ENABLE_PRIVATE_CATALOG -eq 1 ]; then
114+
LSR_SOURCE_NS=$LSR_NAMESPACE
115+
fi
116+
${OC} label catalogsource "$LSR_SOURCE" foundationservices.cloudpak.ibm.com=lsr -n "$CSR_SOURCE_NS" --overwrite=true 2>/dev/null
117+
echo ""
118+
}
119+
120+
function label_ns_and_related() {
121+
122+
title "Start to label the namespaces, operatorgroups... "
123+
124+
# Label the cert manager namespace
125+
${OC} label namespace "$LSR_NAMESPACE" foundationservices.cloudpak.ibm.com=lsr --overwrite=true 2>/dev/null
126+
127+
# Label the cert manager OperatorGroup
128+
operator_group=$(${OC} get operatorgroup -n "$LSR_NAMESPACE" -o jsonpath='{.items[*].metadata.name}')
129+
${OC} label operatorgroup "$operator_group" foundationservices.cloudpak.ibm.com=lsr -n "$LSR_NAMESPACE" --overwrite=true 2>/dev/null
130+
131+
echo ""
132+
}
133+
134+
135+
function label_subscription() {
136+
137+
title "Start to label the Subscriptions... "
138+
local lsr_pm="ibm-license-service-reporter-operator"
139+
${OC} label subscriptions.operators.coreos.com $lsr_pm foundationservices.cloudpak.ibm.com=lsr -n $LSR_NAMESPACE --overwrite=true 2>/dev/null
140+
echo ""
141+
}
142+
143+
function label_lsr() {
144+
145+
title "Start to label the License Service Reporter... "
146+
${OC} label customresourcedefinition ibmlicenseservicereporters.operator.ibm.com foundationservices.cloudpak.ibm.com=lsr --overwrite=true 2>/dev/null
147+
148+
info "Start to label the LSR instances"
149+
lsr_instances=$(${OC} get ibmlicenseservicereporters.operator.ibm.com -n $LSR_NAMESPACE -o jsonpath='{.items[*].metadata.name}')
150+
while IFS= read -r lsr_instance; do
151+
${OC} label ibmlicenseservicereporters.operator.ibm.com $lsr_instance foundationservices.cloudpak.ibm.com=lsr -n $LSR_NAMESPACE --overwrite=true 2>/dev/null
152+
153+
# Label the secrets with OIDC configured
154+
client_secret_name=$(${OC} get ibmlicenseservicereporters.operator.ibm.com $lsr_instance -n $LSR_NAMESPACE -o yaml | awk -F '--client-secret-name=' '{print $2}' | tr -d '"' | tr -d '\n')
155+
${OC} label secret $client_secret_name foundationservices.cloudpak.ibm.com=lsr -n $LSR_NAMESPACE --overwrite=true 2>/dev/null
156+
157+
provider_ca_secret_name=$(${OC} get ibmlicenseservicereporters.operator.ibm.com $lsr_instance -n $LSR_NAMESPACE -o yaml | awk -F '--provider-ca-secret-name=' '{print $2}' | tr -d '"' | tr -d '\n')
158+
${OC} label secret $provider_ca_secret_name foundationservices.cloudpak.ibm.com=lsr -n $LSR_NAMESPACE --overwrite=true 2>/dev/null
159+
done <<< "$lsr_instances"
160+
161+
info "Start to label the necessary secrets"
162+
secrets=$(${OC} get secrets -n $LSR_NAMESPACE | grep ibm-license-service-reporter-token | cut -d ' ' -f1)
163+
for secret in ${secrets[@]}; do
164+
${OC} label secret $secret foundationservices.cloudpak.ibm.com=lsr -n $LSR_NAMESPACE --overwrite=true 2>/dev/null
165+
done
166+
secrets=$(${OC} get secrets -n $LSR_NAMESPACE | grep ibm-license-service-reporter-credential | cut -d ' ' -f1)
167+
for secret in ${secrets[@]}; do
168+
${OC} label secret $secret foundationservices.cloudpak.ibm.com=lsr -n $LSR_NAMESPACE --overwrite=true 2>/dev/null
169+
done
170+
171+
echo ""
172+
}
173+
174+
# ---------- Info functions ----------#
175+
176+
function msg() {
177+
printf '%b\n' "$1"
178+
}
179+
180+
function success() {
181+
msg "\33[32m[✔] ${1}\33[0m"
182+
}
183+
184+
function error() {
185+
msg "\33[31m[✘] ${1}\33[0m"
186+
exit 1
187+
}
188+
189+
function title() {
190+
msg "\33[34m# ${1}\33[0m"
191+
}
192+
193+
function info() {
194+
msg "[INFO] ${1}"
195+
}
196+
197+
function warning() {
198+
msg "\33[33m[✗] ${1}\33[0m"
199+
}
200+
201+
main $*
202+
203+
# ---------------- finish ----------------

velero/spectrum-fusion/license-service-reporter/backup-restore-workflow.yaml

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,22 @@ spec:
5757
type: resource
5858
- includedResourceTypes:
5959
- catalogsources.operators.coreos.com
60-
labelSelector: foundationservices.cloudpak.ibm.com=catalog
61-
name: common-services-catalogs
62-
type: resource
63-
- includedNamespaces:
64-
- openshift-config
65-
includedResourceTypes:
66-
- secrets
67-
labelSelector: foundationservices.cloudpak.ibm.com=pull-secret
68-
name: pull-secret
69-
type: resource
70-
- backupRef: pull-secret
71-
includedNamespaces:
72-
- openshift-config
73-
includedResourceTypes:
74-
- secrets
75-
labelSelector: foundationservices.cloudpak.ibm.com=pull-secret
76-
name: ow-pull-secret
77-
restoreOverwriteResources: true
60+
labelSelector: foundationservices.cloudpak.ibm.com=lsr
61+
name: license-service-reporter-catalog
7862
type: resource
7963
- includeClusterResources: true
80-
labelSelector: foundationservices.cloudpak.ibm.com=namespace
81-
name: common-services-namespace
64+
labelSelector: foundationservices.cloudpak.ibm.com=lsr
65+
name: license-service-reporter-namespace
8266
type: resource
8367
- includedResourceTypes:
8468
- operatorgroups.operators.coreos.com
85-
labelSelector: foundationservices.cloudpak.ibm.com=operatorgroup
86-
name: common-services-operatorgroups
69+
labelSelector: foundationservices.cloudpak.ibm.com=lsr
70+
name: license-service-reporter-operatorgroup
8771
type: resource
8872
- includedResourceTypes:
8973
- subscriptions.operators.coreos.com
9074
labelSelector: foundationservices.cloudpak.ibm.com=lsr
91-
name: license-service-reporter-subscriptions
75+
name: license-service-reporter-subscription
9276
type: resource
9377
hooks:
9478
- chks:
@@ -119,23 +103,20 @@ spec:
119103
- failOn: any-error
120104
name: backup
121105
sequence:
122-
- group: pull-secret
123-
- group: common-services-namespace
124-
- group: common-services-catalogs
125-
- group: common-services-operatorgroups
106+
- group: license-service-reporter-namespace
107+
- group: license-service-reporter-catalog
108+
- group: license-service-reporter-operatorgroup
126109
- group: license-service-reporter-parent
127-
- group: license-service-reporter-subscriptions
110+
- group: license-service-reporter-subscription
128111
- failOn: any-error
129112
name: restore
130113
sequence:
131-
- group: common-services-namespace
132-
- group: pull-secret
133-
- group: ow-pull-secret
134-
- group: common-services-catalogs
135-
- group: common-services-operatorgroups
114+
- group: license-service-reporter-namespace
115+
- group: license-service-reporter-catalog
116+
- group: license-service-reporter-operatorgroup
136117
- group: license-service-reporter-crd
137118
- group: license-service-reporter-instances
138-
- group: license-service-reporter-subscriptions
119+
- group: license-service-reporter-subscription
139120
- hook: license-service-reporter-check/podReady
140121
- hook: license-service-reporter-instance-check/podReady
141122
---

velero/spectrum-fusion/recipes/4.0-4.5-example-recipe-multi-ns.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ spec:
9393
includedResourceTypes:
9494
- customresourcedefinitions.apiextensions.k8s.io
9595
labelSelector: foundationservices.cloudpak.ibm.com=crd
96-
name: commonservices-crd
96+
name: commonservice-crd
9797
type: resource
9898
- includedResourceTypes:
9999
- commonservices.operator.ibm.com
@@ -370,7 +370,7 @@ spec:
370370
- group: common-services-catalogs
371371
- group: common-services-operatorgroups
372372
- group: common-services-configmaps
373-
- group: commonservices-crd
373+
- group: commonservice-crd
374374
- group: commonservice-cr
375375
- group: nss-resources
376376
- group: cs-operator-permissions
@@ -398,7 +398,7 @@ spec:
398398
- group: licensing-resources
399399
# restore common services
400400
- group: common-services-configmaps
401-
- group: commonservices-crd
401+
- group: commonservice-crd
402402
- group: commonservice-cr
403403
- group: nss-resources
404404
- group: common-services-subscriptions

velero/spectrum-fusion/recipes/4.7-example-recipe-multi-ns-multi-zen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ spec:
134134
includedResourceTypes:
135135
- customresourcedefinitions.apiextensions.k8s.io
136136
labelSelector: foundationservices.cloudpak.ibm.com=crd
137-
name: commonservices-crd
137+
name: commonservice-crd
138138
type: resource
139139
- includedResourceTypes:
140140
- commonservices.operator.ibm.com
@@ -573,7 +573,7 @@ spec:
573573
- hook: lsr-data/restore
574574
# restore common services
575575
- group: common-services-configmaps
576-
- group: commonservices-crd
576+
- group: commonservice-crd
577577
- group: commonservice-cr
578578
- group: nss-resources
579579
- group: common-services-subscriptions

velero/spectrum-fusion/recipes/4.7-example-recipe-multi-ns.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ spec:
136136
includedResourceTypes:
137137
- customresourcedefinitions.apiextensions.k8s.io
138138
labelSelector: foundationservices.cloudpak.ibm.com=crd
139-
name: commonservices-crd
139+
name: commonservice-crd
140140
type: resource
141141
- includedResourceTypes:
142142
- commonservices.operator.ibm.com
@@ -479,7 +479,7 @@ spec:
479479
- group: singleton-subscriptions
480480
- group: cert-manager-resources
481481
- group: license-service-reporter-subscriptions
482-
- group: commonservices-crd
482+
- group: commonservice-crd
483483
- group: commonservice-cr
484484
- group: nss-resources
485485
- group: common-services-subscriptions
@@ -515,7 +515,7 @@ spec:
515515
- hook: lsr-data/restore
516516
# restore common services
517517
- group: common-services-configmaps
518-
- group: commonservices-crd
518+
- group: commonservice-crd
519519
- group: commonservice-cr
520520
- group: nss-resources
521521
- group: common-services-subscriptions

0 commit comments

Comments
 (0)