Skip to content

Commit

Permalink
Upgrade script updates (init container) (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshatdell authored Mar 3, 2023
1 parent 348d89e commit 47500ef
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 113 deletions.
1 change: 1 addition & 0 deletions deploy/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rules:
resources:
- customresourcedefinitions
verbs:
- create
- get
- list
- update
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dell/goiscsi v1.4.0 // indirect
github.com/dell/gonvme v1.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ github.com/dustmop/soup v1.1.2-0.20190516214245-38228baa104e/go.mod h1:CgNC6SGbT
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw=
github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=
github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
1 change: 1 addition & 0 deletions helm/csm-replication/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rules:
resources:
- customresourcedefinitions
verbs:
- create
- get
- list
- update
Expand Down
2 changes: 1 addition & 1 deletion repctl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions repctl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw=
github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=
github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
42 changes: 20 additions & 22 deletions scripts/upgrade/migrate_rg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,43 @@
set -e

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
RGVERSION="replication.storage.dell.com/v1alpha1"
ALPHAVERSION="v1alpha1"

echo "ReplicationGroup version migration started."
echo "ReplicationGroup CRD version migration started."

rgVersions=$(kubectl get rg -o=jsonpath='{range .items[*]}{.apiVersion}{"\n"}{end}' 2>&1)
echo -e "ReplicationGroup API versions found:\n$rgVersions"
crdVersion=$(kubectl get customresourcedefinitions dellcsireplicationgroups.replication.storage.dell.com -o=jsonpath='{.status.storedVersions}' 2>&1)
echo -e "ReplicationGroup CRD version found: $crdVersion"
found=false
for rgVersion in $rgVersions
do
if [ $rgVersion == $RGVERSION ]
then
found=true
break
fi
done

if [[ $crdVersion == *$ALPHAVERSION* ]]
then
found=true
fi

if $found
then
echo "Alpha versions found. Starting migration..."
echo "Alpha version found. Starting migration..."

echo "Step-1: Updating CRD with both v1alpha1 and v1 versions"
echo "Step-1: Updating replicationgroup CRD with both v1alpha1 and v1 versions"
kubectl replace -f "${SCRIPTDIR}"/replicationcrds.v1alpha1-v1.yaml

echo "Step-2: Migrating ReplicationGroups to v1 version"
rgs=$(kubectl get rg -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>&1)
echo "Step-2: Migrating replicationgroup CRs to v1 version"
rgs=$(kubectl get dellcsireplicationgroup -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>&1)
echo -e "ReplicationGroup IDs:\n$rgs"
for rg in $rgs
do
kubectl get rg $rg -o json | kubectl replace -f -
kubectl get dellcsireplicationgroup $rg -o json | kubectl replace -f -
done

echo "Step-3: Updating CRD to remove v1alpha1 from stored versions"
echo "Step-3: Updating replicationgroup CRD to remove v1alpha1 from stored versions"
kubectl patch customresourcedefinitions dellcsireplicationgroups.replication.storage.dell.com --subresource='status' --type='merge' -p '{"status":{"storedVersions":["v1"]}}'

echo "Step-4: Updating CRD to remove v1alpha1 version"
echo "Step-4: Updating replicationgroup CRD to remove v1alpha1 version"
kubectl replace -f "${SCRIPTDIR}"/replicationcrds.v1.yaml

echo "Step-5: Creating new migrationgroup CRD"
kubectl apply -f "${SCRIPTDIR}"/replicationcrds.migration-v1.yaml
else
echo "No alpha versions found. Skipping migration."
echo "No alpha version found. Skipping migration."
fi

echo "ReplicationGroup version migration completed."
echo "ReplicationGroup CRD version migration completed."
83 changes: 83 additions & 0 deletions scripts/upgrade/replicationcrds.migration-v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: dellcsimigrationgroups.replication.storage.dell.com
spec:
group: replication.storage.dell.com
names:
kind: DellCSIMigrationGroup
listKind: DellCSIMigrationGroupList
plural: dellcsimigrationgroups
shortNames:
- mg
singular: dellcsimigrationgroup
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .metadata.creationTimestamp
name: AGE
type: date
- description: State of the CR
jsonPath: .status.state
name: State
type: string
- description: Source ID
jsonPath: .spec.sourceID
name: Source ID
type: string
- description: Target ID
jsonPath: .spec.targetID
name: Target ID
type: string
name: v1
schema:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: DellCSIMigrationGroupSpec defines the desired state of DellCSIMigrationGroup
properties:
driverName:
type: string
migrationGroupAttributes:
additionalProperties:
type: string
type: object
sourceID:
type: string
targetID:
type: string
required:
- driverName
- migrationGroupAttributes
- sourceID
- targetID
type: object
status:
description: DellCSIMigrationGroupStatus defines the observed state of
DellCSIMigrationGroup
properties:
lastAction:
type: string
state:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
85 changes: 0 additions & 85 deletions scripts/upgrade/replicationcrds.v1.yaml
Original file line number Diff line number Diff line change
@@ -1,88 +1,3 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: dellcsimigrationgroups.replication.storage.dell.com
spec:
group: replication.storage.dell.com
names:
kind: DellCSIMigrationGroup
listKind: DellCSIMigrationGroupList
plural: dellcsimigrationgroups
shortNames:
- mg
singular: dellcsimigrationgroup
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .metadata.creationTimestamp
name: AGE
type: date
- description: State of the CR
jsonPath: .status.state
name: State
type: string
- description: Source ID
jsonPath: .spec.sourceID
name: Source ID
type: string
- description: Target ID
jsonPath: .spec.targetID
name: Target ID
type: string
name: v1
schema:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: DellCSIMigrationGroupSpec defines the desired state of DellCSIMigrationGroup
properties:
driverName:
type: string
migrationGroupAttributes:
additionalProperties:
type: string
type: object
sourceID:
type: string
targetID:
type: string
required:
- driverName
- migrationGroupAttributes
- sourceID
- targetID
type: object
status:
description: DellCSIMigrationGroupStatus defines the observed state of
DellCSIMigrationGroup
properties:
lastAction:
type: string
state:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down

0 comments on commit 47500ef

Please sign in to comment.