├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature-request.md ├── pull_request_template.md └── workflows │ ├── build.yml │ ├── pull_request.yml │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── GOVERNANCE.md ├── LICENSE ├── MAINTAINERS ├── Makefile ├── Makefile.buildx.mk ├── README.md ├── RELEASE.md ├── build ├── build.sh ├── buildxpush.sh ├── deploy.sh ├── migrate │ ├── Dockerfile │ └── migrate.Dockerfile └── upgrade │ ├── Dockerfile │ └── upgrade.Dockerfile ├── changelogs └── released │ ├── v2.3.0-RC1 │ ├── 32-shubham14bajpai │ ├── 65-shubham14bajpai │ └── 66-shubham14bajpai │ ├── v2.4.0-RC1 │ ├── 74-shubham14bajpai │ └── 75-shubham14bajpai │ ├── v2.6.0-RC1 │ ├── 85-shubham14bajpai │ ├── 86-shubham14bajpai │ └── 88-shubham14bajpai │ ├── v2.7.0-RC1 │ ├── 95-shubham14bajpai │ └── 96-shubham14bajpai │ └── v2.8.0-RC1 │ └── 89-shubham14bajpai ├── ci ├── migrate │ ├── application.tmp.yaml │ ├── migrationCRD.yaml │ ├── openebs-operator.yaml │ ├── pool.tmp.yaml │ ├── sanity.sh │ ├── setup.sh │ ├── test.sh │ └── volume.tmp.yaml └── upgrade │ ├── cstor │ ├── application.tmp.yaml │ ├── cstor-operator.tmp.yaml │ ├── ndm-operator.yaml │ ├── pool.tmp.yaml │ ├── sanity.sh │ ├── setup.sh │ ├── test.sh │ └── volume.tmp.yaml │ ├── jiva │ ├── application.yaml │ ├── jiva-operator.tmp.yaml │ ├── sanity.sh │ ├── setup.sh │ ├── test.sh │ └── volume.tmp.yaml │ └── upgradetaskCRD.yaml ├── cmd ├── migrate │ ├── executor │ │ ├── cstor_pool.go │ │ ├── cstor_volume.go │ │ ├── options.go │ │ ├── resource.go │ │ └── setup_job.go │ └── main.go ├── upgrade │ ├── executor │ │ ├── cstor_cspc.go │ │ ├── cstor_volume.go │ │ ├── error.go │ │ ├── jiva_volume.go │ │ ├── options.go │ │ ├── resource.go │ │ └── setup_job.go │ └── main.go └── util │ ├── env.go │ └── error.go ├── docs ├── migration.md ├── upgrade.md ├── verify_cstor_bds.sh └── virtual-disk-troubleshoot.md ├── e2e-tests ├── Dockerfile ├── experiments │ ├── cspc_csi_migration │ │ ├── README.md │ │ ├── application_scale.yml │ │ ├── cstor-spc-migration-job.j2 │ │ ├── cstor-volume-migration-job.j2 │ │ ├── cstor_replica_version_check.yml │ │ ├── run_e2e_test.yml │ │ ├── test.yml │ │ └── test_vars.yml │ ├── cspc_csi_upgrade │ │ ├── README.md │ │ ├── cstor-csi-volume-upgrade-job.j2 │ │ ├── cstor-cspc-upgrade-job.j2 │ │ ├── cstor_replica_version_check.yml │ │ ├── run_e2e_test.yml │ │ ├── test.yml │ │ └── test_vars.yml │ ├── cstor-operator-provision │ │ ├── README.md │ │ ├── run_e2e_test.yml │ │ ├── test.yml │ │ └── test_vars.yml │ └── openebs-provision │ │ ├── helm_provision.yml │ │ ├── operator_provision.yml │ │ ├── run_e2e_test.yml │ │ ├── test.yml │ │ └── test_vars.yml ├── hack │ ├── crds.yaml │ ├── e2e-result.j2 │ ├── push │ └── rbac.yaml └── utils │ ├── create_testname.yml │ └── update_e2e_result_resource.yml ├── examples ├── migrate │ ├── cstor-volume-migration.yaml │ └── spc-migration.yaml └── upgrade │ ├── cstor-cspc.yaml │ ├── cstor-volume.yaml │ └── jiva-volume.yaml ├── go.mod ├── go.sum └── pkg ├── migrate └── cstor │ ├── backup_restore.go │ ├── blockdevice_correction.go │ ├── cspc_generator.go │ ├── cspc_generator_test.go │ ├── cstorvolumepolicy.go │ ├── cstorvolumepolicy_test.go │ ├── helper.go │ ├── interface.go │ ├── migrationtask.go │ ├── pool.go │ ├── snapshot.go │ ├── volume.go │ └── volume_operations.go ├── upgrade ├── exec.go ├── patch │ ├── cspc.go │ ├── cspi.go │ ├── cv.go │ ├── cvc.go │ ├── cvr.go │ ├── deployment.go │ ├── interface.go │ ├── jivavolume.go │ ├── rollout_status.go │ ├── rollout_status_test.go │ ├── service.go │ └── statefulset.go └── upgrader │ ├── cstor_cspc.go │ ├── cstor_cspi.go │ ├── cstor_cvr.go │ ├── cstor_volume.go │ ├── helper.go │ ├── helper_test.go │ ├── interface.go │ ├── jiva_volume.go │ ├── register.go │ ├── resourcepatch.go │ ├── upgrade.go │ └── upgradetask.go └── version ├── util.go └── version.go /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug encountered while upgrading openebs volumes/pools 4 | labels: kind/bug 5 | 6 | --- 7 | 8 | 11 | 12 | **Describe the bug:** A clear and concise description of what the bug is. 13 | 14 | **Expected behaviour:** A concise description of what you expected to happen 15 | 16 | **Steps to reproduce the bug:** 17 | Steps to reproduce the bug should be clear and easily reproducible to help people gain an understanding of the problem 18 | 19 | **The output of the following commands will help us better understand what's going on**: 20 | 21 | 22 | * `kubectl get pods -n --show-labels` 23 | * `kubectl logs -n ` 24 | 25 | **Anything else we need to know?:** 26 | Add any other context about the problem here. 27 | 28 | **Environment details:** 29 | - OpenEBS version (use `kubectl get po -n openebs --show-labels`): 30 | - Kubernetes version (use `kubectl version`): 31 | - Cloud provider or hardware configuration: 32 | - OS (e.g: `cat /etc/os-release`): 33 | - kernel (e.g: `uname -a`): 34 | - others: -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea to improve openebs upgrades 4 | labels: Enhancement 5 | 6 | --- 7 | 8 | **Describe the problem/challenge you have** 9 | [A description of the current limitation/problem/challenge that you are experiencing.] 10 | 11 | 12 | **Describe the solution you'd like** 13 | [A clear and concise description of what you want to happen.] 14 | 15 | 16 | **Anything else you would like to add:** 17 | [Miscellaneous information that will assist in solving the issue.] 18 | 19 | 20 | **Environment:** 21 | - OpenEBS version (use `kubectl get po -n openebs --show-labels`): 22 | - Kubernetes version (use `kubectl version`): 23 | - Cloud provider or hardware configuration: 24 | - OS (e.g: `cat /etc/os-release`): 25 | - kernel (e.g: `uname -a`): 26 | - others: -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | **What this PR does**: 8 | 9 | **Which issue(s) this PR fixes**: 10 | Fixes # 11 | 12 | 13 | **Special notes for your reviewer**: 14 | 15 | **Checklist** 16 | - [ ] PR messages has document related information 17 | - [ ] Labelled this PR & related issue with `documentation` tag 18 | - [ ] PR messages has breaking changes related information 19 | - [ ] PR messages has upgrade related information 20 | - [ ] Labelled this PR & related issue with `requires-upgrade` tag 21 | - [ ] Tests updated -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | /bin/ 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.so 7 | *.dylib 8 | 9 | # Test binary, built with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # Dependency directories (remove the comment below to include it) 16 | # vendor/ 17 | 18 | # IDE files 19 | .idea/ -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at community@openebs.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /GOVERNANCE.md: -------------------------------------------------------------------------------- 1 | This is a OpenEBS sub project and abides by the 2 | [OpenEBS Project Governance](https://github.com/openebs/openebs/blob/master/GOVERNANCE.md). 3 | -------------------------------------------------------------------------------- /MAINTAINERS: -------------------------------------------------------------------------------- 1 | # Official list of OpenEBS Maintainers. 2 | # 3 | # Names added to this file should be in the following format: 4 | # Individual's name,@githubhandle, Company Name 5 | # 6 | # Each of the OpenEBS sub project may have one or more of the 7 | # following maintainers and list of reviewers who are 8 | # in the process of becoming maintainers. 9 | # 10 | # 11 | # Each reviewer can be part of one or more GitHub 12 | # team aliases created for maintaining sub projects. 13 | # Current active team aliases for sub projects are: 14 | # - control-plane-maintainers 15 | # 16 | # Please keep the below list sorted in ascending order. 17 | # 18 | #Maintainers 19 | "Kiran Mova",@kmova,MayaData 20 | "Vishnu Itta",@vishnuitta,MayaData 21 | 22 | #Reviewers 23 | "Ashutosh Kumar",@sonasingh46,MayaData #control-plane-maintainers 24 | "Prateek Pandey",@prateekpandey14,MayaData #control-plane-maintainers 25 | "Shubham Bajpai",@shubham14bajpai,MayaData #control-plane-maintainers 26 | -------------------------------------------------------------------------------- /Makefile.buildx.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018-2020 The OpenEBS Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # ============================================================================== 16 | # Build Options 17 | 18 | ifeq (${TAG}, ) 19 | export TAG=ci 20 | endif 21 | 22 | # Build upgrade & migrate docker image with buildx 23 | # Experimental docker feature to build cross platform multi-architecture docker images 24 | # https://docs.docker.com/buildx/working-with-buildx/ 25 | 26 | # default list of platforms for which multiarch image is built 27 | ifeq (${PLATFORMS}, ) 28 | export PLATFORMS="linux/amd64,linux/arm64" 29 | endif 30 | 31 | # if IMG_RESULT is unspecified, by default the image will be pushed to registry 32 | ifeq (${IMG_RESULT}, load) 33 | export PUSH_ARG="--load" 34 | # if load is specified, image will be built only for the build machine architecture. 35 | export PLATFORMS="local" 36 | else ifeq (${IMG_RESULT}, cache) 37 | # if cache is specified, image will only be available in the build cache, it won't be pushed or loaded 38 | # therefore no PUSH_ARG will be specified 39 | else 40 | export PUSH_ARG="--push" 41 | endif 42 | 43 | # Name of the multiarch image for upgrade job 44 | DOCKERX_IMAGE_UPGRADE:=${IMAGE_ORG}/upgrade:${TAG} 45 | 46 | # Name of the multiarch image for migrate job 47 | DOCKERX_IMAGE_MIGRATE:=${IMAGE_ORG}/migrate:${TAG} 48 | 49 | .PHONY: docker.buildx 50 | docker.buildx: 51 | export DOCKER_CLI_EXPERIMENTAL=enabled 52 | @if ! docker buildx ls | grep -q container-builder; then\ 53 | docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ 54 | fi 55 | @docker buildx build --platform ${PLATFORMS} \ 56 | -t "$(DOCKERX_IMAGE_NAME)" ${DBUILD_ARGS} -f $(PWD)/build/$(COMPONENT)/$(COMPONENT).Dockerfile \ 57 | . ${PUSH_ARG} 58 | @echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)" 59 | @echo 60 | 61 | .PHONY: docker.buildx.upgrade 62 | docker.buildx.upgrade: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_UPGRADE) 63 | docker.buildx.upgrade: COMPONENT=$(UPGRADE) 64 | docker.buildx.upgrade: docker.buildx 65 | 66 | .PHONY: docker.buildx.migrate 67 | docker.buildx.migrate: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_MIGRATE) 68 | docker.buildx.migrate: COMPONENT=$(MIGRATE) 69 | docker.buildx.migrate: docker.buildx 70 | 71 | .PHONY: buildx.push.upgrade 72 | buildx.push.upgrade: 73 | BUILDX=true DIMAGE=${IMAGE_ORG}/upgrade ./build/buildxpush.sh 74 | 75 | .PHONY: buildx.push.migrate 76 | buildx.push.migrate: 77 | BUILDX=true DIMAGE=${IMAGE_ORG}/migrate ./build/buildxpush.sh 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Upgrade 2 | 3 | [![Build Status](https://github.com/openebs/upgrade/actions/workflows/build.yml/badge.svg)](https://github.com/openebs/upgrade/actions/workflows/build.yml) 4 | [![Go Report](https://goreportcard.com/badge/github.com/openebs/upgrade)](https://goreportcard.com/report/github.com/openebs/upgrade) 5 | [![codecov](https://codecov.io/gh/openebs/upgrade/branch/master/graph/badge.svg)](https://codecov.io/gh/openebs/upgrade) 6 | [![Slack](https://img.shields.io/badge/chat!!!-slack-ff1493.svg?style=flat-square)](https://kubernetes.slack.com/messages/openebs) 7 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopenebs%2Fupgrade.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopenebs%2Fupgrade?ref=badge_shield) 8 | 9 | 10 | Contains components that help with OpenEBS data engine upgrades 11 | 12 | 13 | ## [Upgrading OpenEBS reources](https://github.com/openebs/upgrade/blob/master/docs/upgrade.md) 14 | Below are the steps for upgrading the OpenEBS reources: 15 | - [CSPC pools](https://github.com/openebs/upgrade/blob/master/docs/upgrade.md#cspc-pools) 16 | - [cStor CSI volumes](https://github.com/openebs/upgrade/blob/master/docs/upgrade.md#cstor-csi-volumes) 17 | - [jiva CSI volumes](https://github.com/openebs/upgrade/blob/master/docs/upgrade.md#jiva-csi-volumes) 18 | 19 | **Note:** 20 | - If current version of ndm-operator is 1.12.0 or below and using virtual disks as blockdevices for provisioning cStor pool please refer this [doc](https://github.com/openebs/upgrade/blob/master/docs/virtual-disk-troubleshoot.md) before proceeding. 21 | - After upgrading the cStor or Jiva control plane, you have to upgrade Jiva/cStor pools and volumes to the latest control plane version as early as possible. While Jiva/cStor pools and volumes will continue to work, the management operations like **_Ongoing Pool/Volume Provisioning, Volume Expansion, Volume Replica Migration, cStor Pool Scaleup/Scaledown, cStor VolumeReplica Scaling, cStor Pool Expansion_** will **not be supported** due to difference in control plane and pools/volumes version. 22 | 23 | ## [Migrating cStor pools and volumes from SPC to CSPC](https://github.com/openebs/upgrade/blob/master/docs/migration.md) 24 | Below are the steps for migrating the OpenEBS cStor custom reources: 25 | - [SPC pools to CSPC pools](https://github.com/openebs/upgrade/blob/master/docs/migration.md#spc-pools-to-cspc-pools) 26 | - [cStor External Provisioned volumes to cStor CSI volumes](https://github.com/openebs/upgrade/blob/master/docs/migration.md#cstor-external-provisioned-volumes-to-cstor-csi-volumes) 27 | 28 | ## [Migrating jiva volumes to CSI spec](https://github.com/openebs/upgrade/blob/master/docs/migration.md#migrating-jiva-external-provisioned-volumes-to-jiva-csi-volumes-experimental) 29 | 30 | **Note:** 31 | - If the Kubernetes cluster is on rancher and iscsi is running inside the kubelet container then it is mandatory to install iscsi service on the nodes and add extra binds to the kubelet container as mentioned [here](https://github.com/openebs/cstor-operators/blob/master/docs/troubleshooting/rancher_prerequisite.md). 32 | - Minimum version of Kubernetes to migrate to CSPC pools / CSI volumes is 1.17.0. 33 | - If using virtual disks as blockdevices for provisioning cStorpool please refer this [doc](https://github.com/openebs/upgrade/blob/master/docs/virtual-disk-troubleshoot.md) before proceeding. 34 | 35 | 36 | 37 | ## License 38 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopenebs%2Fupgrade.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopenebs%2Fupgrade?ref=badge_large) 39 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Release Process 2 | upgrade follows a monthly release cadence. The scope of the release is determined by contributor availability. The scope is published in the [Release Tracker Projects](https://github.com/orgs/openebs/projects). 3 | 4 | ## Release Candidate Verification Checklist 5 | 6 | Every release has release candidate builds that are created starting from the third week into the release. These release candidate builds help to freeze the scope and maintain the quality of the release. The release candidate builds will go through: 7 | - Platform Verification 8 | - Regression and Feature Verification Automated tests. 9 | - Exploratory testing by QA engineers 10 | - Strict security scanners on the container images 11 | - Upgrade from previous releases 12 | - Beta testing by users on issues that they are interested in. 13 | - Dogfooding on OpenEBS workload and e2e infrastructure clusters. 14 | 15 | If any issues are found during the above stages, they are fixed and a new release candidate builds are generated. 16 | 17 | Once all the above tests are completed, a main release tagged image is published. 18 | 19 | ## Release Tagging 20 | 21 | upgrade is released as a set of container images with a versioned tag. 22 | 23 | Before creating a release, the repo owner needs to create a separate branch from the active branch, which is `master`. Name of the branch should follow the naming convention of `v.1.12.x` if the release is for v1.12.0. 24 | 25 | Once the release branch is created, changelog from `changelogs/unreleased` needs to be moved to release specific folder `changelogs/v1.12.x`, if release branch is `v2.0.x` then folder will be `changelogs/v2.0.x`. 26 | 27 | The format of the release tag is either "Release-Name-RC1" or "Release-Name" depending on whether the tag is a release candidate or a release. (Example: v1.12.0-RC1 is a GitHub release tag for the upgrade release build. v1.12.0 is the release tag that is created after the release criteria are satisfied by the upgrade builds.) 28 | 29 | Once the release is triggered, github actions release workflow process has to be monitored. Once github actions release workflow is passed images are pushed to docker hub and quay.io. Images can be verified by going through docker hub and quay.io. Also the images shouldn't have any high-level vulnerabilities. 30 | 31 | Images for the different components are published at the following location: 32 | 33 | - Upgrade
34 | https://quay.io/repository/openebs/upgrade-amd64?tab=tags
35 | https://hub.docker.com/r/openebs/upgrade-amd64/tags
36 | 37 | - Migrate
38 | https://quay.io/repository/openebs/migrate-amd64?tab=tags
39 | https://hub.docker.com/r/openebs/migrate-amd64/tags
40 | 41 | 42 | Once a release is created, update the release description with the changelog mentioned in `changelog/v1.12.x`. Once the changelogs are updated in the release, the repo owner needs to create a PR to `master` with the following details: 43 | 1. update the changelog from `changelog/v1.12.x` to `upgrade/CHANGELOG.md` 44 | 2. If a release is not an RC tag then PR should include the changes to remove `changelog/v1.12.x` folder. 45 | 3. If a release is an RC tag then PR should include the changes to remove the changelog from `changelog/v1.12.x` which are already mentioned in `upgrade/CHANGELOG.md` as part of step number 1. -------------------------------------------------------------------------------- /build/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2020 The OpenEBS Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # This script builds the application from source for multiple platforms. 18 | set -e 19 | 20 | # Get the parent directory of where this script is. 21 | SOURCE="${BASH_SOURCE[0]}" 22 | while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 23 | DIR="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )" 24 | 25 | # Change into that directory 26 | cd "$DIR" 27 | 28 | # Get the git commit 29 | if [ -f $GOPATH/src/github.com/openebs/upgrade/GITCOMMIT ]; 30 | then 31 | GIT_COMMIT="$(cat $GOPATH/src/github.com/openebs/upgrade/GITCOMMIT)" 32 | else 33 | GIT_COMMIT="$(git rev-parse HEAD)" 34 | fi 35 | 36 | # Set BUILDMETA based on release tag 37 | if [[ -n "$RELEASE_TAG" ]] && [[ $RELEASE_TAG != *"RC"* ]]; then 38 | echo "released" > BUILDMETA 39 | fi 40 | 41 | # Get the version details 42 | # Determine the current branch 43 | CURRENT_BRANCH="" 44 | if [ -z "${BRANCH}" ]; 45 | then 46 | CURRENT_BRANCH=$(git branch | grep "\*" | cut -d ' ' -f2) 47 | else 48 | CURRENT_BRANCH="${BRANCH}" 49 | fi 50 | 51 | ## Populate the version based on release tag 52 | ## If release tag is set then assign it as VERSION and 53 | ## if release tag is empty then mark version as ci 54 | if [ -n "$RELEASE_TAG" ]; then 55 | # Trim the `v` from the RELEASE_TAG if it exists 56 | # Example: v1.10.0 maps to 1.10.0 57 | # Example: 1.10.0 maps to 1.10.0 58 | # Example: v1.10.0-custom maps to 1.10.0-custom 59 | VERSION="${RELEASE_TAG#v}" 60 | else 61 | ## Marking VERSION as current_branch-dev 62 | ## Example: master branch maps to master-dev 63 | ## Example: v1.11.x-ee branch to 1.11.x-ee-dev 64 | ## Example: v1.10.x branch to 1.10.x-dev 65 | VERSION="${CURRENT_BRANCH#v}-dev" 66 | fi 67 | 68 | echo "Building for ${VERSION} VERSION" 69 | 70 | #VERSION=$(git describe --tags --always --dirty) 71 | 72 | # Determine the arch/os combos we're building for 73 | UNAME=$(uname) 74 | ARCH=$(uname -m) 75 | if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then 76 | echo "Sorry, this OS is not supported yet." 77 | exit 1 78 | fi 79 | 80 | if [ "$UNAME" = "Darwin" ] ; then 81 | XC_OS="darwin" 82 | elif [ "$UNAME" = "Linux" ] ; then 83 | XC_OS="linux" 84 | fi 85 | 86 | if [ -z "${PNAME}" ]; 87 | then 88 | echo "Project name not defined" 89 | exit 1 90 | fi 91 | 92 | if [ -z "${CTLNAME}" ]; 93 | then 94 | echo "CTLNAME not defined" 95 | exit 1 96 | fi 97 | 98 | # Delete the old dir 99 | echo "==> Removing old directory..." 100 | rm -rf bin/${PNAME}/* 101 | mkdir -p bin/${PNAME}/ 102 | 103 | # If its dev mode, only build for ourself 104 | if [[ "${DEV}" ]]; then 105 | XC_OS=$(go env GOOS) 106 | XC_ARCH=$(go env GOARCH) 107 | fi 108 | 109 | # Build! 110 | echo "==> Building ${CTLNAME} using $(go version)... " 111 | 112 | GOOS="${XC_OS}" 113 | GOARCH="${XC_ARCH}" 114 | output_name="bin/${PNAME}/"$GOOS"_"$GOARCH"/"$CTLNAME 115 | 116 | if [ $GOOS = "windows" ]; then 117 | output_name+='.exe' 118 | fi 119 | 120 | env GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build ${BUILD_TAG} -ldflags \ 121 | "-X github.com/openebs/upgrade/pkg/version.GitCommit=${GIT_COMMIT} \ 122 | -X main.CtlName='${CTLNAME}' \ 123 | -X github.com/openebs/upgrade/pkg/version.Version=${VERSION}"\ 124 | -o $output_name \ 125 | ./cmd/${CTLNAME} 126 | 127 | echo "" 128 | 129 | # Move all the compiled things to the $GOPATH/bin 130 | GOPATH=${GOPATH:-$(go env GOPATH)} 131 | case $(uname) in 132 | CYGWIN*) 133 | GOPATH="$(cygpath $GOPATH)" 134 | ;; 135 | esac 136 | OLDIFS=$IFS 137 | IFS=: MAIN_GOPATH=($GOPATH) 138 | IFS=$OLDIFS 139 | 140 | # Create the gopath bin if not already available 141 | mkdir -p ${MAIN_GOPATH}/bin/ 142 | 143 | # Copy our OS/Arch to the bin/ directory 144 | DEV_PLATFORM="./bin/${PNAME}/$(go env GOOS)_$(go env GOARCH)" 145 | for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 2 -type f); do 146 | cp ${F} bin/${PNAME}/ 147 | cp ${F} ${MAIN_GOPATH}/bin/ 148 | done 149 | 150 | # Done! 151 | echo 152 | echo "==> Results:" 153 | ls -hl bin/${PNAME}/ -------------------------------------------------------------------------------- /build/buildxpush.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019-2020 The OpenEBS Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | 19 | if [ -z ${DIMAGE} ]; 20 | then 21 | echo "Error: DIMAGE is not specified"; 22 | exit 1 23 | fi 24 | 25 | function pushBuildx() { 26 | BUILD_TAG="latest" 27 | TARGET_IMG=${DIMAGE} 28 | 29 | # TODO Currently ci builds with commit tag will not be generated, 30 | # since buildx does not support multiple repo 31 | # if not a release build set the tag and ci image 32 | if [ -z "${RELEASE_TAG}" ]; then 33 | return 34 | # BUILD_ID=$(git describe --tags --always) 35 | # BUILD_TAG="${BRANCH}-${BUILD_ID}" 36 | # TARGET_IMG="${DIMAGE}-ci" 37 | fi 38 | 39 | echo "Tagging and pushing ${DIMAGE}:${TAG} as ${TARGET_IMG}:${BUILD_TAG}" 40 | docker buildx imagetools create "${DIMAGE}:${TAG}" -t "${TARGET_IMG}:${BUILD_TAG}" 41 | } 42 | 43 | # if the push is for a buildx build 44 | if [[ ${BUILDX} ]]; then 45 | pushBuildx 46 | exit 0 47 | fi 48 | -------------------------------------------------------------------------------- /build/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2020 The OpenEBS Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -e 17 | 18 | # Determine the arch/os we're building for 19 | ARCH=$(uname -m) 20 | 21 | if [ "${ARCH}" = "x86_64" ]; then 22 | UPGRADE_IMG="${IMAGE_ORG}/upgrade-amd64" 23 | MIGRATE_IMG="${IMAGE_ORG}/migrate-amd64" 24 | elif [ "${ARCH}" = "aarch64" ]; then 25 | UPGRADE_IMG="${IMAGE_ORG}/upgrade-arm64" 26 | MIGRATE_IMG="${IMAGE_ORG}/migrate-arm64" 27 | fi 28 | 29 | curl --fail https://raw.githubusercontent.com/openebs/charts/gh-pages/scripts/release/buildscripts/push > ./build/push 30 | chmod +x ./build/push 31 | 32 | # tag and push all the images 33 | DIMAGE="${UPGRADE_IMG}" ./build/push 34 | DIMAGE="${MIGRATE_IMG}" ./build/push -------------------------------------------------------------------------------- /build/migrate/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This builds openebs migratte image using 16 | # its latest binary 17 | # 18 | 19 | FROM alpine:3.11.5 20 | 21 | # copy the latest binary 22 | COPY migrate /usr/local/bin/migrate 23 | 24 | ARG ARCH 25 | ARG DBUILD_DATE 26 | ARG DBUILD_REPO_URL 27 | ARG DBUILD_SITE_URL 28 | LABEL org.label-schema.name="migrate" 29 | LABEL org.label-schema.description="migrates openebs components" 30 | LABEL org.label-schema.schema-version="1.0" 31 | LABEL org.label-schema.build-date=$DBUILD_DATE 32 | LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL 33 | LABEL org.label-schema.url=$DBUILD_SITE_URL 34 | 35 | ENTRYPOINT ["migrate"] 36 | -------------------------------------------------------------------------------- /build/migrate/migrate.Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2020 The OpenEBS Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # This Dockerfile builds migrate 16 | # 17 | FROM golang:1.19.11 as build 18 | 19 | ARG RELEASE_TAG 20 | ARG BRANCH 21 | ARG TARGETOS 22 | ARG TARGETARCH 23 | ARG TARGETVARIANT="" 24 | 25 | ENV GO111MODULE=on \ 26 | GOOS=${TARGETOS} \ 27 | GOARCH=${TARGETARCH} \ 28 | GOARM=${TARGETVARIANT} \ 29 | DEBIAN_FRONTEND=noninteractive \ 30 | PATH="/root/go/bin:${PATH}" \ 31 | RELEASE_TAG=${RELEASE_TAG} \ 32 | BRANCH=${BRANCH} 33 | 34 | WORKDIR /go/src/github.com/openebs/upgrade/ 35 | 36 | RUN apt-get update && apt-get install -y make git 37 | 38 | COPY go.mod go.sum ./ 39 | # Get dependancies - will also be cached if we won't change mod/sum 40 | RUN go mod download 41 | 42 | COPY . . 43 | 44 | RUN make migrate 45 | 46 | FROM alpine:3.11.5 47 | 48 | ARG DBUILD_DATE 49 | ARG DBUILD_REPO_URL 50 | ARG DBUILD_SITE_URL 51 | LABEL org.label-schema.name="migrate" 52 | LABEL org.label-schema.description="migrate openebs components" 53 | LABEL org.label-schema.schema-version="1.0" 54 | LABEL org.label-schema.build-date=$DBUILD_DATE 55 | LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL 56 | LABEL org.label-schema.url=$DBUILD_SITE_URL 57 | 58 | # copy the latest binary 59 | COPY --from=build /go/src/github.com/openebs/upgrade/bin/migrate/migrate /usr/local/bin/migrate 60 | 61 | ENTRYPOINT ["migrate"] 62 | -------------------------------------------------------------------------------- /build/upgrade/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This builds openebs upgrade image using 16 | # its latest binary 17 | # 18 | 19 | FROM alpine:3.11.5 20 | 21 | # copy the latest binary 22 | COPY upgrade /usr/local/bin/upgrade 23 | 24 | ARG ARCH 25 | ARG DBUILD_DATE 26 | ARG DBUILD_REPO_URL 27 | ARG DBUILD_SITE_URL 28 | LABEL org.label-schema.name="upgrade" 29 | LABEL org.label-schema.description="upgrades openebs components" 30 | LABEL org.label-schema.schema-version="1.0" 31 | LABEL org.label-schema.build-date=$DBUILD_DATE 32 | LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL 33 | LABEL org.label-schema.url=$DBUILD_SITE_URL 34 | 35 | ENTRYPOINT ["upgrade"] 36 | -------------------------------------------------------------------------------- /build/upgrade/upgrade.Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2020 The OpenEBS Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # This Dockerfile builds upgrade 16 | # 17 | FROM golang:1.19.11 as build 18 | 19 | ARG RELEASE_TAG 20 | ARG BRANCH 21 | ARG TARGETOS 22 | ARG TARGETARCH 23 | ARG TARGETVARIANT="" 24 | 25 | ENV GO111MODULE=on \ 26 | GOOS=${TARGETOS} \ 27 | GOARCH=${TARGETARCH} \ 28 | GOARM=${TARGETVARIANT} \ 29 | DEBIAN_FRONTEND=noninteractive \ 30 | PATH="/root/go/bin:${PATH}" \ 31 | RELEASE_TAG=${RELEASE_TAG} \ 32 | BRANCH=${BRANCH} 33 | 34 | WORKDIR /go/src/github.com/openebs/upgrade/ 35 | 36 | RUN apt-get update && apt-get install -y make git 37 | 38 | COPY go.mod go.sum ./ 39 | # Get dependancies - will also be cached if we won't change mod/sum 40 | RUN go mod download 41 | 42 | COPY . . 43 | 44 | RUN make upgrade 45 | 46 | FROM alpine:3.11.5 47 | 48 | ARG DBUILD_DATE 49 | ARG DBUILD_REPO_URL 50 | ARG DBUILD_SITE_URL 51 | LABEL org.label-schema.name="upgrade" 52 | LABEL org.label-schema.description="upgrades openebs components" 53 | LABEL org.label-schema.schema-version="1.0" 54 | LABEL org.label-schema.build-date=$DBUILD_DATE 55 | LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL 56 | LABEL org.label-schema.url=$DBUILD_SITE_URL 57 | 58 | # copy the latest binary 59 | COPY --from=build /go/src/github.com/openebs/upgrade/bin/upgrade/upgrade /usr/local/bin/upgrade 60 | 61 | ENTRYPOINT ["upgrade"] 62 | -------------------------------------------------------------------------------- /changelogs/released/v2.3.0-RC1/32-shubham14bajpai: -------------------------------------------------------------------------------- 1 | chore(build): add support for multiarch build 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.3.0-RC1/65-shubham14bajpai: -------------------------------------------------------------------------------- 1 | feat(migrate): add support for CR status reporting 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.3.0-RC1/66-shubham14bajpai: -------------------------------------------------------------------------------- 1 | refact(deps): use openebs/api v2 release modules 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.4.0-RC1/74-shubham14bajpai: -------------------------------------------------------------------------------- 1 | fix(travis): increase wait time for pods 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.4.0-RC1/75-shubham14bajpai: -------------------------------------------------------------------------------- 1 | chore(version): add 2.4.0 to upgrade matrix 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.6.0-RC1/85-shubham14bajpai: -------------------------------------------------------------------------------- 1 | fix(migrate): update lock file path when csp is scaled down 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.6.0-RC1/86-shubham14bajpai: -------------------------------------------------------------------------------- 1 | chore(crd): update upgradeTask CRD to v1 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.6.0-RC1/88-shubham14bajpai: -------------------------------------------------------------------------------- 1 | feat(upgrade): remove the -amd64 suffix from images 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.7.0-RC1/95-shubham14bajpai: -------------------------------------------------------------------------------- 1 | chore(actions): move travis tests to github action 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.7.0-RC1/96-shubham14bajpai: -------------------------------------------------------------------------------- 1 | refact(migrate): improve logs and docs about multiple cstorvolume apis 2 | -------------------------------------------------------------------------------- /changelogs/released/v2.8.0-RC1/89-shubham14bajpai: -------------------------------------------------------------------------------- 1 | feat(upgrade): add support for jiva-csi volume upgrades 2 | -------------------------------------------------------------------------------- /ci/migrate/application.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | #Use the following YAMLs to create a cStor Storage Pool. 17 | apiVersion: openebs.io/v1alpha1 18 | kind: StoragePoolClaim 19 | metadata: 20 | name: sparse-claim 21 | annotations: 22 | cas.openebs.io/config: | 23 | - name: PoolResourceRequests 24 | value: |- 25 | memory: 2Gi 26 | - name: PoolResourceLimits 27 | value: |- 28 | memory: 4Gi 29 | spec: 30 | name: sparse-claim 31 | type: sparse 32 | poolSpec: 33 | poolType: striped 34 | blockDevices: 35 | blockDeviceList: 36 | - SPCBD 37 | --- 38 | apiVersion: storage.k8s.io/v1 39 | kind: StorageClass 40 | metadata: 41 | name: openebs-cstor-sparse 42 | annotations: 43 | openebs.io/cas-type: cstor 44 | cas.openebs.io/config: | 45 | - name: StoragePoolClaim 46 | value: "sparse-claim" 47 | - name: ReplicaCount 48 | value: "1" 49 | - name: TargetResourceLimits 50 | value: |- 51 | memory: 1Gi 52 | cpu: 200m 53 | - name: TargetResourceRequests 54 | value: |- 55 | memory: 500Mi 56 | cpu: 100m 57 | - name: AuxResourceLimits 58 | value: |- 59 | memory: 1Gi 60 | cpu: 200m 61 | - name: AuxResourceRequests 62 | value: |- 63 | memory: 500Mi 64 | cpu: 100m 65 | - name: TargetTolerations 66 | value: |- 67 | t1: 68 | key: "key1" 69 | operator: "Equal" 70 | value: "value1" 71 | effect: "NoSchedule" 72 | t2: 73 | key: "key1" 74 | operator: "Equal" 75 | value: "value1" 76 | effect: "NoExecute" 77 | - name: TargetNodeSelector 78 | value: |- 79 | nodetype: storage 80 | - name: QueueDepth 81 | value: "32" 82 | - name: Luworkers 83 | value: "6" 84 | - name: ZvolWorkers 85 | value: "1" 86 | provisioner: openebs.io/provisioner-iscsi 87 | --- 88 | apiVersion: v1 89 | kind: Service 90 | metadata: 91 | labels: 92 | lkey: lvalue 93 | name: busybox 94 | spec: 95 | clusterIP: None 96 | selector: 97 | lkey: lvalue 98 | --- 99 | apiVersion: apps/v1 100 | kind: StatefulSet 101 | metadata: 102 | name: busybox 103 | labels: 104 | lkey: lvalue 105 | spec: 106 | serviceName: busybox 107 | replicas: 1 108 | selector: 109 | matchLabels: 110 | lkey: lvalue 111 | #The Label "openebs.io/replica-anti-affinity" 112 | #needs to be added in order to distribute volume replicas. 113 | affinity_label: busybox 114 | template: 115 | metadata: 116 | labels: 117 | lkey: lvalue 118 | affinity_label: busybox 119 | spec: 120 | containers: 121 | - name: busybox 122 | image: busybox 123 | imagePullPolicy: IfNotPresent 124 | command: 125 | - sh 126 | - -c 127 | - 'date > /busybox/date.txt; sync; sleep 5; sync; tail -f /dev/null;' 128 | volumeMounts: 129 | - name: testclaim 130 | mountPath: /busybox 131 | volumeClaimTemplates: 132 | - metadata: 133 | name: testclaim 134 | spec: 135 | accessModes: [ "ReadWriteOnce" ] 136 | storageClassName: openebs-cstor-sparse 137 | resources: 138 | requests: 139 | storage: 2G 140 | 141 | -------------------------------------------------------------------------------- /ci/migrate/pool.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: batch/v1 16 | kind: Job 17 | metadata: 18 | # the name can be of the form migrate- 19 | name: migrate-pool 20 | namespace: openebs 21 | spec: 22 | backoffLimit: 0 23 | template: 24 | spec: 25 | #VERIFY the value of serviceAccountName is pointing to service account 26 | # created within openebs namespace. Use the non-default account. 27 | # by running `kubectl get sa -n ` 28 | serviceAccountName: openebs-maya-operator 29 | containers: 30 | - name: migrate 31 | args: 32 | - "cstor-spc" 33 | # name of the spc that is to be migrated 34 | - "--spc-name=sparse-claim" 35 | # optional flag to rename the spc to a specific name 36 | # - "--cspc-name=sparse-claim-migrated" 37 | #Following are optional parameters 38 | #Log Level 39 | - "--v=4" 40 | #DO NOT CHANGE BELOW PARAMETERS 41 | env: 42 | - name: OPENEBS_NAMESPACE 43 | valueFrom: 44 | fieldRef: 45 | fieldPath: metadata.namespace 46 | tty: true 47 | # the version of the image should be same the 48 | # version of cstor-operator installed. 49 | image: imageorg/migrate-amd64:ci 50 | restartPolicy: Never 51 | -------------------------------------------------------------------------------- /ci/migrate/sanity.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2020 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | sudo modprobe iscsi_tcp 18 | 19 | make migrate-image.amd64 20 | 21 | # To test the sanity in different customized 22 | # image prefixes 23 | if [ -z "${IMAGE_ORG}" ]; then 24 | IMAGE_ORG="openebs"; 25 | export IMAGE_ORG; 26 | fi 27 | 28 | # To test the sanity in different versioned branches 29 | # and release tags, get the release version and corresponding 30 | # image tags 31 | # Determine the current branch 32 | CURRENT_BRANCH="" 33 | if [ -z "${BRANCH}" ]; 34 | then 35 | CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) 36 | else 37 | CURRENT_BRANCH="${BRANCH}" 38 | fi 39 | 40 | TEST_IMAGE_TAG="${CURRENT_BRANCH}-ci" 41 | if [ ${CURRENT_BRANCH} = "develop" ]; then 42 | TEST_IMAGE_TAG="ci" 43 | fi 44 | TEST_VERSION="${CURRENT_BRANCH}-dev" 45 | 46 | if [ -n "$RELEASE_TAG" ]; then 47 | # Trim the `v` from the RELEASE_TAG if it exists 48 | # Example: v1.10.0 maps to 1.10.0 49 | # Example: 1.10.0 maps to 1.10.0 50 | # Example: v1.10.0-custom maps to 1.10.0-custom 51 | TEST_IMAGE_TAG="${RELEASE_TAG#v}" 52 | TEST_VERSION="${RELEASE_TAG#v}" 53 | fi 54 | 55 | export TEST_IMAGE_TAG="${TEST_IMAGE_TAG#v}" 56 | export TEST_VERSION="${TEST_VERSION#v}" 57 | 58 | echo "Testing migrate for org: $IMAGE_ORG version: $TEST_VERSION imagetag: $TEST_IMAGE_TAG" 59 | 60 | # setup openebs & cstor v1 for migration 61 | ./ci/migrate/setup.sh || exit 1 62 | # run migration tests 63 | ./ci/migrate/test.sh 64 | if [[ $? != 0 ]]; then 65 | kubectl describe pods 66 | kubectl describe pods -n openebs 67 | kubectl logs --tail=50 -l job-name=migrate-pool -n openebs 68 | kubectl logs --tail=50 -l job-name=migrate-volume -n openebs 69 | exit 1 70 | fi 71 | 72 | rm ./ci/migrate/volume.yaml ./ci/migrate/application.yaml 73 | -------------------------------------------------------------------------------- /ci/migrate/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2020 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -ex 18 | 19 | echo "Install openebs-operator 1.11.0" 20 | 21 | kubectl apply -f ./ci/migrate/openebs-operator.yaml 22 | sleep 5 23 | 24 | echo "Wait for maya-apiserver to start" 25 | 26 | kubectl wait --for=condition=available --timeout=600s deployment/maya-apiserver -n openebs 27 | 28 | echo "Label the node" 29 | 30 | kubectl label nodes --all nodetype=storage 31 | 32 | echo "Create application with cStor volume on SPC" 33 | 34 | bdname=$(kubectl -n openebs get blockdevices -o jsonpath='{.items[?(@.spec.details.deviceType=="sparse")].metadata.name}') 35 | sed "s/SPCBD/$bdname/" ./ci/migrate/application.tmp.yaml > ./ci/migrate/application.yaml 36 | kubectl apply -f ./ci/migrate/application.yaml 37 | sleep 5 38 | kubectl wait --for=condition=Ready pod -l lkey=lvalue --timeout=600s 39 | 40 | echo "Install cstor & csi operators" 41 | 42 | kubectl apply -f ./ci/migrate/migrationCRD.yaml 43 | wget https://raw.githubusercontent.com/openebs/charts/gh-pages/cstor-operator.yaml 44 | sed -ie '/SPARSE_FILE_COUNT/{n;s/"0"/"1"/}' cstor-operator.yaml 45 | kubectl apply -f cstor-operator.yaml 46 | sleep 5 47 | 48 | sed "s|testimage|$TEST_IMAGE_TAG|g" ./ci/upgrade/cstor/cstor-operator.tmp.yaml | sed "s|testversion|$TEST_VERSION|g" | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/migrate/cstor-operator.yaml 49 | kubectl apply -f ./ci/migrate/cstor-operator.yaml 50 | sleep 10 51 | 52 | kubectl wait --for=condition=available --timeout=600s deployment/cspc-operator -n openebs -------------------------------------------------------------------------------- /ci/migrate/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2020 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -ex 18 | 19 | echo "Scaling down application before migration" 20 | 21 | kubectl scale statefulset busybox --replicas=0 22 | kubectl wait --for=delete pod -l lkey=lvalue --timeout=600s 23 | 24 | echo "Migrating pool to cspc" 25 | 26 | sed "s|imageorg|$IMAGE_ORG|g" ./ci/migrate/pool.tmp.yaml > ./ci/migrate/pool.yaml 27 | kubectl apply -f ./ci/migrate/pool.yaml 28 | sleep 5 29 | kubectl wait --for=condition=complete job/migrate-pool -n openebs --timeout=550s 30 | kubectl logs --tail=50 -l job-name=migrate-pool -n openebs 31 | 32 | echo "Migrating extetnal volume to csi volume" 33 | 34 | pvname=$(kubectl get pvc testclaim-busybox-0 -o jsonpath="{.spec.volumeName}") 35 | sed "s|PVNAME|$pvname|g" ./ci/migrate/volume.tmp.yaml | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/migrate/volume.yaml 36 | kubectl apply -f ./ci/migrate/volume.yaml 37 | sleep 5 38 | kubectl wait --for=condition=complete job/migrate-volume -n openebs --timeout=550s 39 | kubectl logs --tail=50 -l job-name=migrate-volume -n openebs 40 | 41 | echo "Scaling up application after migration" 42 | 43 | kubectl scale statefulset busybox --replicas=1 44 | sleep 5 45 | kubectl wait --for=condition=Ready pod -l lkey=lvalue --timeout=600s -------------------------------------------------------------------------------- /ci/migrate/volume.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --- 15 | apiVersion: batch/v1 16 | kind: Job 17 | metadata: 18 | # the name can be of the form migrate-cstor- 19 | name: migrate-volume 20 | namespace: openebs 21 | spec: 22 | backoffLimit: 0 23 | template: 24 | spec: 25 | #VERIFY the value of serviceAccountName is pointing to service account 26 | # created within openebs namespace. Use the non-default account. 27 | # by running `kubectl get sa -n ` 28 | serviceAccountName: openebs-maya-operator 29 | containers: 30 | - name: migrate 31 | args: 32 | - "cstor-volume" 33 | # name of the pv that is to be migrated 34 | - "--pv-name=PVNAME" 35 | 36 | #Following are optional parameters 37 | #Log Level 38 | - "--v=4" 39 | #DO NOT CHANGE BELOW PARAMETERS 40 | env: 41 | - name: OPENEBS_NAMESPACE 42 | valueFrom: 43 | fieldRef: 44 | fieldPath: metadata.namespace 45 | tty: true 46 | # the version of the image should be same the 47 | # version of cstor-operator installed. 48 | image: imageorg/migrate-amd64:ci 49 | restartPolicy: OnFailure 50 | --- 51 | 52 | -------------------------------------------------------------------------------- /ci/upgrade/cstor/application.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: cstor.openebs.io/v1 16 | kind: CStorPoolCluster 17 | metadata: 18 | name: cspc-stripe 19 | namespace: openebs 20 | spec: 21 | pools: 22 | - nodeSelector: 23 | kubernetes.io/hostname: "NODENAME" 24 | dataRaidGroups: 25 | - blockDevices: 26 | - blockDeviceName: "CSPCBD" 27 | poolConfig: 28 | dataRaidGroupType: "stripe" 29 | --- 30 | kind: StorageClass 31 | apiVersion: storage.k8s.io/v1 32 | metadata: 33 | name: openebs-cstor-csi 34 | provisioner: cstor.csi.openebs.io 35 | allowVolumeExpansion: true 36 | parameters: 37 | cas-type: cstor 38 | cstorPoolCluster: cspc-stripe 39 | replicaCount: "1" 40 | --- 41 | kind: PersistentVolumeClaim 42 | apiVersion: v1 43 | metadata: 44 | name: demo-csi-vol-claim 45 | spec: 46 | storageClassName: openebs-cstor-csi 47 | accessModes: 48 | - ReadWriteOnce 49 | resources: 50 | requests: 51 | storage: 5Gi 52 | --- 53 | apiVersion: apps/v1 54 | kind: Deployment 55 | metadata: 56 | name: percona 57 | labels: 58 | lkey: lvalue 59 | openebs.io/target-affinity: percona 60 | spec: 61 | replicas: 1 62 | selector: 63 | matchLabels: 64 | lkey: lvalue 65 | template: 66 | metadata: 67 | labels: 68 | lkey: lvalue 69 | openebs.io/target-affinity: percona 70 | spec: 71 | containers: 72 | - resources: 73 | limits: 74 | cpu: 0.5 75 | name: percona 76 | image: openebs/tests-custom-percona:latest 77 | imagePullPolicy: IfNotPresent 78 | args: 79 | - "--ignore-db-dir" 80 | - "lost+found" 81 | env: 82 | - name: MYSQL_ROOT_PASSWORD 83 | value: k8sDem0 84 | ports: 85 | - containerPort: 3306 86 | name: percona 87 | volumeMounts: 88 | - mountPath: /var/lib/mysql 89 | name: data-vol 90 | # 91 | livenessProbe: 92 | exec: 93 | command: ["bash", "sql-test.sh"] 94 | initialDelaySeconds: 60 95 | periodSeconds: 1 96 | timeoutSeconds: 10 97 | # 98 | volumes: 99 | - name: data-vol 100 | persistentVolumeClaim: 101 | claimName: demo-csi-vol-claim 102 | --- 103 | apiVersion: v1 104 | kind: Service 105 | metadata: 106 | name: percona-csi-mysql 107 | labels: 108 | lkey: lvalue 109 | spec: 110 | ports: 111 | - port: 3306 112 | targetPort: 3306 113 | selector: 114 | lkey: lvalue 115 | -------------------------------------------------------------------------------- /ci/upgrade/cstor/pool.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This is an example YAML for upgrading cstor CSPC. 16 | # Some of the values below needs to be changed to 17 | # match your openebs installation. The fields are 18 | # indicated with VERIFY 19 | --- 20 | apiVersion: batch/v1 21 | kind: Job 22 | metadata: 23 | # VERIFY that you have provided a unique name for this upgrade job. 24 | # The name can be any valid K8s string for name. 25 | name: upgrade-pool 26 | 27 | # VERIFY the value of namespace is same as the namespace where openebs components 28 | # are installed. You can verify using the command: 29 | # `kubectl get pods -n -l openebs.io/component-name=maya-apiserver` 30 | # The above command should return status of the openebs-apiserver. 31 | namespace: openebs 32 | spec: 33 | backoffLimit: 0 34 | template: 35 | spec: 36 | # VERIFY the value of serviceAccountName is pointing to service account 37 | # created within openebs namespace. Use the non-default account. 38 | # by running `kubectl get sa -n ` 39 | serviceAccountName: openebs-cstor-operator 40 | containers: 41 | - name: upgrade 42 | args: 43 | - "cstor-cspc" 44 | 45 | # --from-version is the current version of the pool 46 | - "--from-version=2.0.0" 47 | 48 | # --to-version is the version desired upgrade version 49 | - "--to-version=testversion" 50 | # if required the image prefix of the pool deployments can be 51 | # changed using the flag below, defaults to whatever was present on old 52 | # deployments. 53 | - "--to-version-image-prefix=imageorg/" 54 | # if required the image tags for pool deployments can be changed 55 | # to a custom image tag using the flag below, 56 | # defaults to the --to-version mentioned above. 57 | - "--to-version-image-tag=testimage" 58 | 59 | # VERIFY that you have provided the correct list of CSPC Names 60 | - "cspc-stripe" 61 | 62 | # Following are optional parameters 63 | # Log Level 64 | - "--v=4" 65 | # DO NOT CHANGE BELOW PARAMETERS 66 | env: 67 | - name: OPENEBS_NAMESPACE 68 | valueFrom: 69 | fieldRef: 70 | fieldPath: metadata.namespace 71 | tty: true 72 | 73 | # the image version should be same as the --to-version mentioned above 74 | # in the args of the job 75 | image: imageorg/upgrade:ci 76 | imagePullPolicy: IfNotPresent 77 | restartPolicy: Never 78 | --- 79 | 80 | -------------------------------------------------------------------------------- /ci/upgrade/cstor/sanity.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2020 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | set -x 19 | 20 | sudo modprobe iscsi_tcp 21 | 22 | # To test the sanity in different customized 23 | # image prefixes 24 | if [[ "${IMAGE_ORG}" == "" ]]; then 25 | IMAGE_ORG="openebs"; 26 | export IMAGE_ORG; 27 | fi 28 | 29 | # To test the sanity in different versioned branches 30 | # and release tags, get the release version and corresponding 31 | # image tags 32 | # Determine the current branch 33 | CURRENT_BRANCH="" 34 | if [ -z "${BRANCH}" ]; 35 | then 36 | CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) 37 | else 38 | CURRENT_BRANCH="${BRANCH}" 39 | fi 40 | 41 | TEST_IMAGE_TAG="${CURRENT_BRANCH}-ci" 42 | if [ "${CURRENT_BRANCH}" = "develop" ]; then 43 | TEST_IMAGE_TAG="ci" 44 | fi 45 | TEST_VERSION="${CURRENT_BRANCH}-dev" 46 | 47 | if [ -n "$RELEASE_TAG" ]; then 48 | # Trim the `v` from the RELEASE_TAG if it exists 49 | # Example: v1.10.0 maps to 1.10.0 50 | # Example: 1.10.0 maps to 1.10.0 51 | # Example: v1.10.0-custom maps to 1.10.0-custom 52 | TEST_IMAGE_TAG="${RELEASE_TAG#v}" 53 | TEST_VERSION="${RELEASE_TAG#v}" 54 | fi 55 | 56 | export TEST_IMAGE_TAG="${TEST_IMAGE_TAG#v}" 57 | export TEST_VERSION="${TEST_VERSION#v}" 58 | 59 | echo "Testing upgrade for org: $IMAGE_ORG version: $TEST_VERSION imagetag: $TEST_IMAGE_TAG" 60 | 61 | # setup openebs & cstor v1 for migration 62 | ./ci/upgrade/cstor/setup.sh || exit 1 63 | # run migration tests 64 | ./ci/upgrade/cstor/test.sh 65 | if [ $? != 0 ]; then 66 | kubectl logs -l job-name=upgrade-pool -n openebs 67 | kubectl logs -l job-name=upgrade-volume -n openebs 68 | kubectl describe pods -n openebs 69 | kubectl describe deploy -n openebs 70 | exit 1 71 | fi 72 | 73 | rm ./ci/upgrade/cstor/volume.yaml ./ci/upgrade/cstor/application.yaml 74 | -------------------------------------------------------------------------------- /ci/upgrade/cstor/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2020 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | set -ex 19 | 20 | echo "Install cstor-operators in 2.0.0" 21 | 22 | kubectl create ns openebs 23 | 24 | kubectl apply -f https://openebs.github.io/charts/versioned/2.8.0/cstor-operator.yaml \ 25 | -f ./ci/upgrade/cstor/ndm-operator.yaml 26 | sleep 100 27 | 28 | echo "Wait for cspc-operator to start" 29 | 30 | kubectl wait --for=condition=available --timeout=550s deployment/cspc-operator -n openebs 31 | 32 | echo "Create application with cStor volume on CSPC" 33 | 34 | nodename=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}') 35 | bdname=$(kubectl -n openebs get blockdevices -o jsonpath='{.items[?(@.spec.details.deviceType=="sparse")].metadata.name}') 36 | sed "s|CSPCBD|$bdname|g" ./ci/upgrade/cstor/application.tmp.yaml | sed "s|NODENAME|$nodename|g" > ./ci/upgrade/cstor/application.yaml 37 | kubectl apply -f ./ci/upgrade/cstor/application.yaml 38 | sleep 10 39 | kubectl wait --for=condition=available --timeout=200s deployment/percona 40 | 41 | echo "Upgrade control plane to latest version" 42 | 43 | sed "s|testimage|$TEST_IMAGE_TAG|g" ./ci/upgrade/cstor/cstor-operator.tmp.yaml | sed "s|testversion|$TEST_VERSION|g" | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/upgrade/cstor/cstor-operator.yaml 44 | 45 | kubectl delete csidriver cstor.csi.openebs.io 46 | 47 | kubectl apply -f https://raw.githubusercontent.com/openebs/cstor-operators/develop/deploy/cstor-operator.yaml \ 48 | -f ./ci/upgrade/cstor/cstor-operator.yaml 49 | 50 | sleep 10 51 | kubectl wait --for=condition=available --timeout=300s deployment/cspc-operator -n openebs 52 | 53 | kubectl apply -f ./ci/upgrade/upgradetaskCRD.yaml 54 | -------------------------------------------------------------------------------- /ci/upgrade/cstor/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2020 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -ex 18 | 19 | echo "Upgrading CSPC pool" 20 | 21 | sed "s|testimage|$TEST_IMAGE_TAG|g" ./ci/upgrade/cstor/pool.tmp.yaml | sed "s|testversion|$TEST_VERSION|g" | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/upgrade/cstor/pool.yaml 22 | kubectl apply -f ./ci/upgrade/cstor/pool.yaml 23 | sleep 5 24 | kubectl wait --for=condition=complete job/upgrade-pool -n openebs --timeout=550s 25 | kubectl logs --tail=50 -l job-name=upgrade-pool -n openebs 26 | 27 | echo "Upgrading CSI volume" 28 | 29 | pvname=$(kubectl get pvc demo-csi-vol-claim -o jsonpath="{.spec.volumeName}") 30 | sed "s|PVNAME|$pvname|g" ./ci/upgrade/cstor/volume.tmp.yaml | sed "s|testimage|$TEST_IMAGE_TAG|g" | sed "s|testversion|$TEST_VERSION|g" | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/upgrade/cstor/volume.yaml 31 | kubectl apply -f ./ci/upgrade/cstor/volume.yaml 32 | sleep 5 33 | kubectl wait --for=condition=complete job/upgrade-volume -n openebs --timeout=550s 34 | kubectl logs --tail=50 -l job-name=upgrade-volume -n openebs 35 | -------------------------------------------------------------------------------- /ci/upgrade/cstor/volume.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This is an example YAML for upgrading cstor volume. 16 | # Some of the values below needs to be changed to 17 | # match your openebs installation. The fields are 18 | # indicated with VERIFY 19 | --- 20 | apiVersion: batch/v1 21 | kind: Job 22 | metadata: 23 | # VERIFY that you have provided a unique name for this upgrade job. 24 | # The name can be any valid K8s string for name. 25 | name: upgrade-volume 26 | 27 | # VERIFY the value of namespace is same as the namespace where openebs components 28 | # are installed. You can verify using the command: 29 | # `kubectl get pods -n -l openebs.io/component-name=maya-apiserver` 30 | # The above command should return status of the openebs-apiserver. 31 | namespace: openebs 32 | spec: 33 | backoffLimit: 0 34 | template: 35 | spec: 36 | # VERIFY the value of serviceAccountName is pointing to service account 37 | # created within openebs namespace. Use the non-default account. 38 | # by running `kubectl get sa -n ` 39 | serviceAccountName: openebs-cstor-operator 40 | containers: 41 | - name: upgrade 42 | args: 43 | - "cstor-volume" 44 | 45 | # --from-version is the current version of the volume 46 | - "--from-version=2.0.0" 47 | 48 | # --to-version is the version desired upgrade version 49 | - "--to-version=testversion" 50 | # if required the image prefix of the volume deployments can be 51 | # changed using the flag below, defaults to whatever was present on old 52 | # deployments. 53 | - "--to-version-image-prefix=imageorg/" 54 | # if required the image tags for volume deployments can be changed 55 | # to a custom image tag using the flag below, 56 | # defaults to the --to-version mentioned above. 57 | - "--to-version-image-tag=testimage" 58 | 59 | # VERIFY that you have provided the correct list of volume Names 60 | - "PVNAME" 61 | 62 | # Following are optional parameters 63 | # Log Level 64 | - "--v=4" 65 | # DO NOT CHANGE BELOW PARAMETERS 66 | env: 67 | - name: OPENEBS_NAMESPACE 68 | valueFrom: 69 | fieldRef: 70 | fieldPath: metadata.namespace 71 | tty: true 72 | 73 | # the image version should be same as the --to-version mentioned above 74 | # in the args of the job 75 | image: imageorg/upgrade:ci 76 | imagePullPolicy: IfNotPresent 77 | restartPolicy: Never 78 | --- 79 | 80 | -------------------------------------------------------------------------------- /ci/upgrade/jiva/application.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | apiVersion: openebs.io/v1alpha1 17 | kind: JivaVolumePolicy 18 | metadata: 19 | name: example-jivavolumepolicy 20 | namespace: openebs 21 | spec: 22 | replicaSC: openebs-hostpath 23 | enableBufio: false 24 | autoScaling: false 25 | target: 26 | monitor: true 27 | replicationFactor: 1 28 | --- 29 | apiVersion: storage.k8s.io/v1 30 | kind: StorageClass 31 | metadata: 32 | name: openebs-jiva-csi-sc 33 | provisioner: jiva.csi.openebs.io 34 | allowVolumeExpansion: true 35 | parameters: 36 | cas-type: "jiva" 37 | policy: "example-jivavolumepolicy" 38 | --- 39 | kind: PersistentVolumeClaim 40 | apiVersion: v1 41 | metadata: 42 | name: jiva-csi-demo 43 | spec: 44 | storageClassName: openebs-jiva-csi-sc 45 | accessModes: 46 | - ReadWriteOnce 47 | resources: 48 | requests: 49 | storage: 4Gi 50 | --- 51 | apiVersion: apps/v1 52 | kind: Deployment 53 | metadata: 54 | name: fio 55 | spec: 56 | selector: 57 | matchLabels: 58 | name: fio 59 | replicas: 1 60 | strategy: 61 | type: Recreate 62 | rollingUpdate: null 63 | template: 64 | metadata: 65 | labels: 66 | name: fio 67 | spec: 68 | #nodeName: gke-utkarsh-csi-default-pool-953ba289-rt9l 69 | containers: 70 | - name: perfrunner 71 | image: openebs/tests-fio 72 | command: ["/bin/bash"] 73 | args: ["-c", "while true ;do sleep 50; done"] 74 | volumeMounts: 75 | - mountPath: /datadir 76 | name: fio-vol 77 | volumes: 78 | - name: fio-vol 79 | persistentVolumeClaim: 80 | claimName: jiva-csi-demo -------------------------------------------------------------------------------- /ci/upgrade/jiva/jiva-operator.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | apiVersion: apps/v1 17 | kind: Deployment 18 | metadata: 19 | name: jiva-operator 20 | namespace: openebs 21 | labels: 22 | openebs.io/component-name: jiva-operator 23 | openebs.io/version: testversion 24 | name: jiva-operator 25 | spec: 26 | replicas: 1 27 | selector: 28 | matchLabels: 29 | name: jiva-operator 30 | template: 31 | metadata: 32 | labels: 33 | name: jiva-operator 34 | openebs.io/component-name: jiva-operator 35 | openebs.io/version: testversion 36 | spec: 37 | serviceAccountName: jiva-operator 38 | containers: 39 | - name: jiva-operator 40 | # Replace this with the built image name 41 | image: imageorg/jiva-operator:testimage 42 | command: 43 | - jiva-operator 44 | imagePullPolicy: IfNotPresent 45 | env: 46 | - name: OPENEBS_NAMESPACE 47 | valueFrom: 48 | fieldRef: 49 | fieldPath: metadata.namespace 50 | - name: POD_NAME 51 | valueFrom: 52 | fieldRef: 53 | fieldPath: metadata.name 54 | - name: OPERATOR_NAME 55 | value: "jiva-operator" 56 | - name: OPENEBS_IO_JIVA_CONTROLLER_IMAGE 57 | value: "imageorg/jiva:testimage" 58 | - name: OPENEBS_IO_JIVA_REPLICA_IMAGE 59 | value: "imageorg/jiva:testimage" 60 | livenessProbe: 61 | httpGet: 62 | path: /healthz 63 | port: 8282 64 | initialDelaySeconds: 15 65 | periodSeconds: 20 66 | readinessProbe: 67 | httpGet: 68 | path: /readyz 69 | port: 8282 70 | initialDelaySeconds: 5 71 | periodSeconds: 10 72 | resources: 73 | limits: 74 | cpu: 100m 75 | memory: 30Mi 76 | requests: 77 | cpu: 100m 78 | memory: 20Mi 79 | terminationGracePeriodSeconds: 10 80 | -------------------------------------------------------------------------------- /ci/upgrade/jiva/sanity.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2021 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | set -x 19 | 20 | sudo modprobe iscsi_tcp 21 | 22 | # To test the sanity in different customized 23 | # image prefixes 24 | if [[ "${IMAGE_ORG}" == "" ]]; then 25 | IMAGE_ORG="openebs"; 26 | export IMAGE_ORG; 27 | fi 28 | 29 | # To test the sanity in different versioned branches 30 | # and release tags, get the release version and corresponding 31 | # image tags 32 | # Determine the current branch 33 | CURRENT_BRANCH="" 34 | if [ -z "${BRANCH}" ]; 35 | then 36 | CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) 37 | else 38 | CURRENT_BRANCH="${BRANCH}" 39 | fi 40 | 41 | TEST_IMAGE_TAG="${CURRENT_BRANCH}-ci" 42 | if [ "${CURRENT_BRANCH}" = "develop" ]; then 43 | TEST_IMAGE_TAG="ci" 44 | fi 45 | TEST_VERSION="${CURRENT_BRANCH}-dev" 46 | 47 | if [ -n "$RELEASE_TAG" ]; then 48 | # Trim the `v` from the RELEASE_TAG if it exists 49 | # Example: v1.10.0 maps to 1.10.0 50 | # Example: 1.10.0 maps to 1.10.0 51 | # Example: v1.10.0-custom maps to 1.10.0-custom 52 | TEST_IMAGE_TAG="${RELEASE_TAG#v}" 53 | TEST_VERSION="${RELEASE_TAG#v}" 54 | fi 55 | 56 | export TEST_IMAGE_TAG="${TEST_IMAGE_TAG#v}" 57 | export TEST_VERSION="${TEST_VERSION#v}" 58 | 59 | echo "Testing upgrade for org: $IMAGE_ORG version: $TEST_VERSION imagetag: $TEST_IMAGE_TAG" 60 | 61 | # setup openebs & cstor v1 for migration 62 | ./ci/upgrade/jiva/setup.sh || exit 1 63 | # run migration tests 64 | ./ci/upgrade/jiva/test.sh 65 | if [ $? != 0 ]; then 66 | kubectl logs -l job-name=upgrade-volume -n openebs 67 | kubectl describe pods -n openebs 68 | exit 1 69 | fi 70 | 71 | rm ./ci/upgrade/jiva/volume.yaml 72 | -------------------------------------------------------------------------------- /ci/upgrade/jiva/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2021 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | set -ex 19 | 20 | echo "Install jiva-operator in 2.8.0" 21 | 22 | kubectl create ns openebs 23 | 24 | kubectl apply -f https://openebs.github.io/charts/versioned/2.8.0/jiva-operator.yaml \ 25 | -f https://openebs.github.io/charts/versioned/2.8.0/openebs-operator.yaml 26 | sleep 100 27 | 28 | echo "Wait for jiva-operator to start" 29 | 30 | kubectl wait --for=condition=available --timeout=550s deployment/jiva-operator -n openebs 31 | 32 | echo "Create application with jiva volume on openebs-hostpath" 33 | 34 | kubectl apply -f ./ci/upgrade/jiva/application.yaml 35 | sleep 10 36 | kubectl wait --for=condition=available --timeout=200s deployment/fio 37 | 38 | echo "Upgrade control plane to latest version" 39 | 40 | sed "s|testimage|$TEST_IMAGE_TAG|g" ./ci/upgrade/jiva/jiva-operator.tmp.yaml | sed "s|testversion|$TEST_VERSION|g" | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/upgrade/jiva/jiva-operator.yaml 41 | 42 | kubectl apply -f https://raw.githubusercontent.com/openebs/jiva-operator/develop/deploy/jiva-operator.yaml \ 43 | -f ./ci/upgrade/jiva/jiva-operator.yaml 44 | 45 | sleep 50 46 | kubectl wait --for=condition=available --timeout=300s deployment/jiva-operator -n openebs 47 | 48 | kubectl apply -f ./ci/upgrade/upgradetaskCRD.yaml 49 | -------------------------------------------------------------------------------- /ci/upgrade/jiva/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2021 The OpenEBS Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -ex 18 | 19 | echo "Upgrading jiva volume" 20 | 21 | pvname=$(kubectl get pvc jiva-csi-demo -o jsonpath="{.spec.volumeName}") 22 | sed "s|PVNAME|$pvname|g" ./ci/upgrade/jiva/volume.tmp.yaml | sed "s|testimage|$TEST_IMAGE_TAG|g" | sed "s|testversion|$TEST_VERSION|g" | sed "s|imageorg|$IMAGE_ORG|g" > ./ci/upgrade/jiva/volume.yaml 23 | kubectl apply -f ./ci/upgrade/jiva/volume.yaml 24 | sleep 5 25 | kubectl wait --for=condition=complete job/upgrade-volume -n openebs --timeout=550s 26 | kubectl logs --tail=50 -l job-name=upgrade-volume -n openebs 27 | -------------------------------------------------------------------------------- /ci/upgrade/jiva/volume.tmp.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This is an example YAML for upgrading cstor volume. 16 | # Some of the values below needs to be changed to 17 | # match your openebs installation. The fields are 18 | # indicated with VERIFY 19 | --- 20 | apiVersion: batch/v1 21 | kind: Job 22 | metadata: 23 | # VERIFY that you have provided a unique name for this upgrade job. 24 | # The name can be any valid K8s string for name. 25 | name: upgrade-volume 26 | 27 | # VERIFY the value of namespace is same as the namespace where openebs components 28 | # are installed. You can verify using the command: 29 | # `kubectl get pods -n -l openebs.io/component-name=maya-apiserver` 30 | # The above command should return status of the openebs-apiserver. 31 | namespace: openebs 32 | spec: 33 | backoffLimit: 0 34 | template: 35 | spec: 36 | # VERIFY the value of serviceAccountName is pointing to service account 37 | # created within openebs namespace. Use the non-default account. 38 | # by running `kubectl get sa -n ` 39 | serviceAccountName: jiva-operator 40 | containers: 41 | - name: upgrade 42 | args: 43 | - "jiva-volume" 44 | 45 | # --from-version is the current version of the volume 46 | - "--from-version=2.7.0" 47 | 48 | # --to-version is the version desired upgrade version 49 | - "--to-version=testversion" 50 | # if required the image prefix of the volume deployments can be 51 | # changed using the flag below, defaults to whatever was present on old 52 | # deployments. 53 | - "--to-version-image-prefix=imageorg/" 54 | # if required the image tags for volume deployments can be changed 55 | # to a custom image tag using the flag below, 56 | # defaults to the --to-version mentioned above. 57 | - "--to-version-image-tag=testimage" 58 | 59 | # VERIFY that you have provided the correct list of volume Names 60 | - "PVNAME" 61 | 62 | # Following are optional parameters 63 | # Log Level 64 | - "--v=4" 65 | # DO NOT CHANGE BELOW PARAMETERS 66 | env: 67 | - name: OPENEBS_NAMESPACE 68 | valueFrom: 69 | fieldRef: 70 | fieldPath: metadata.namespace 71 | tty: true 72 | 73 | # the image version should be same as the --to-version mentioned above 74 | # in the args of the job 75 | image: imageorg/upgrade:ci 76 | imagePullPolicy: IfNotPresent 77 | restartPolicy: Never 78 | --- 79 | 80 | -------------------------------------------------------------------------------- /cmd/migrate/executor/cstor_pool.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "strings" 21 | 22 | "github.com/openebs/maya/pkg/util" 23 | "github.com/spf13/cobra" 24 | "k8s.io/klog/v2" 25 | 26 | cstor "github.com/openebs/upgrade/pkg/migrate/cstor" 27 | 28 | "github.com/pkg/errors" 29 | ) 30 | 31 | var ( 32 | cstorSPCMigrateCmdHelpText = ` 33 | This command migrates the cStor SPC to CSPC 34 | 35 | Usage: migrate cstor-spc --spc-name 36 | ` 37 | ) 38 | 39 | // NewMigratePoolJob migrates all the cStor Pools associated with 40 | // a given Storage Pool Claim 41 | func NewMigratePoolJob() *cobra.Command { 42 | cmd := &cobra.Command{ 43 | Use: "cstor-spc", 44 | Short: "Migrate cStor SPC", 45 | Long: cstorSPCMigrateCmdHelpText, 46 | Example: `migrate cstor-spc --spc-name `, 47 | Run: func(cmd *cobra.Command, args []string) { 48 | util.CheckErr(options.RunPreFlightChecks(), util.Fatal) 49 | util.CheckErr(options.RunCStorSPCMigrateChecks(), util.Fatal) 50 | util.CheckErr(options.RunCStorSPCMigrate(), util.Fatal) 51 | }, 52 | } 53 | 54 | cmd.Flags().StringVarP(&options.spcName, 55 | "spc-name", "", 56 | options.spcName, 57 | "cstor SPC name to be migrated. Run \"kubectl get spc\", to get spc-name") 58 | 59 | cmd.Flags().StringVarP(&options.cspcName, 60 | "cspc-name", "", 61 | options.cspcName, 62 | "[optional] custom cspc name. By default cspc is created with same name as spc") 63 | 64 | return cmd 65 | } 66 | 67 | // RunCStorSPCMigrateChecks will ensure the sanity of the cstor SPC migrate options 68 | func (m *MigrateOptions) RunCStorSPCMigrateChecks() error { 69 | if len(strings.TrimSpace(m.spcName)) == 0 { 70 | return errors.Errorf("Cannot execute migrate job: cstor spc name is missing") 71 | } 72 | 73 | return nil 74 | } 75 | 76 | // RunCStorSPCMigrate migrates the given spc. 77 | func (m *MigrateOptions) RunCStorSPCMigrate() error { 78 | 79 | klog.Infof("Migrating spc %s to cspc", m.spcName) 80 | migrator := cstor.CSPCMigrator{} 81 | if m.cspcName != "" { 82 | klog.Infof("using custom cspc name as %s", m.cspcName) 83 | migrator.SetCSPCName(m.cspcName) 84 | } 85 | err := migrator.Migrate(m.spcName, m.openebsNamespace) 86 | if err != nil { 87 | klog.Error(err) 88 | return errors.Errorf("Failed to migrate cStor SPC : %s", m.spcName) 89 | } 90 | klog.Infof("Successfully migrated spc %s to cspc", m.spcName) 91 | 92 | klog.Infof("Make sure to migrate the associated PVs, "+ 93 | "to list CStorVolumes for the PVs which are pending migration use `kubectl get cstorvolume.openebs.io -n %s`, "+ 94 | "and to list CStorVolumes for the migrated/CSI PVs use `kubectl get cstorvolume.cstor.openebs.io -n %s`", 95 | m.openebsNamespace, m.openebsNamespace) 96 | return nil 97 | } 98 | -------------------------------------------------------------------------------- /cmd/migrate/executor/cstor_volume.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "strings" 21 | 22 | "github.com/openebs/maya/pkg/util" 23 | "github.com/spf13/cobra" 24 | "k8s.io/klog/v2" 25 | 26 | cstor "github.com/openebs/upgrade/pkg/migrate/cstor" 27 | 28 | "github.com/pkg/errors" 29 | ) 30 | 31 | var ( 32 | cstorVolumeMigrateCmdHelpText = ` 33 | This command migrates the cStor Volume to csi format 34 | 35 | Usage: migrate cstor-volume --pv-name 36 | ` 37 | ) 38 | 39 | // NewMigrateCStorVolumeJob migrates all the cStor Pools associated with 40 | // a given Storage Pool Claim 41 | func NewMigrateCStorVolumeJob() *cobra.Command { 42 | cmd := &cobra.Command{ 43 | Use: "cstor-volume", 44 | Short: "Migrate cStor Volume", 45 | Long: cstorVolumeMigrateCmdHelpText, 46 | Example: `migrate cstor-volume `, 47 | Run: func(cmd *cobra.Command, args []string) { 48 | util.CheckErr(options.RunPreFlightChecks(), util.Fatal) 49 | util.CheckErr(options.RunCStorVolumeMigrateChecks(), util.Fatal) 50 | util.CheckErr(options.RunCStorVolumeMigrate(), util.Fatal) 51 | }, 52 | } 53 | 54 | cmd.Flags().StringVarP(&options.pvName, 55 | "pv-name", "", 56 | options.pvName, 57 | "cstor Volume name to be migrated. Run \"kubectl get pv\", to get pv-name") 58 | 59 | return cmd 60 | } 61 | 62 | // RunCStorVolumeMigrateChecks will ensure the sanity of the cstor Volume migrate options 63 | func (m *MigrateOptions) RunCStorVolumeMigrateChecks() error { 64 | if len(strings.TrimSpace(m.pvName)) == 0 { 65 | return errors.Errorf("Cannot execute migrate job: cstor pv name is missing") 66 | } 67 | 68 | return nil 69 | } 70 | 71 | // RunCStorVolumeMigrate migrates the given pv. 72 | func (m *MigrateOptions) RunCStorVolumeMigrate() error { 73 | 74 | klog.Infof("Migrating volume %s to csi spec", m.pvName) 75 | migrator := cstor.VolumeMigrator{} 76 | err := migrator.Migrate(m.pvName, m.openebsNamespace) 77 | if err != nil { 78 | klog.Error(err) 79 | return errors.Errorf("Failed to migrate cStor Volume : %s", m.pvName) 80 | } 81 | klog.Infof("Successfully migrated volume %s, scale up the application to verify the migration", m.pvName) 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /cmd/migrate/executor/options.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "strings" 21 | 22 | errors "github.com/pkg/errors" 23 | ) 24 | 25 | // MigrateOptions stores information required for migration of 26 | // OpenEBS resources 27 | type MigrateOptions struct { 28 | openebsNamespace string 29 | spcName string 30 | cspcName string 31 | pvName string 32 | resourceKind string 33 | } 34 | 35 | var ( 36 | options = &MigrateOptions{ 37 | openebsNamespace: "openebs", 38 | } 39 | ) 40 | 41 | // RunPreFlightChecks will ensure the sanity of the common migrate options 42 | func (m *MigrateOptions) RunPreFlightChecks() error { 43 | if len(strings.TrimSpace(m.openebsNamespace)) == 0 { 44 | return errors.Errorf("Cannot execute migrate job: openebs namespace is missing") 45 | } 46 | return nil 47 | } 48 | -------------------------------------------------------------------------------- /cmd/migrate/executor/setup_job.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "flag" 21 | "strings" 22 | 23 | "github.com/openebs/upgrade/cmd/util" 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | // NewJob will setup a new migrate job 28 | func NewJob() *cobra.Command { 29 | // Create a new command. 30 | cmd := &cobra.Command{ 31 | Use: "migrate", 32 | Short: "OpenEBS Migrate Utility", 33 | Long: `An utility to migrate OpenEBS SPC Pools to CSPC and Non-CSI Volumes to CSI Volumes, 34 | run as a Kubernetes Job`, 35 | PersistentPreRun: PreRun, 36 | } 37 | 38 | cmd.AddCommand( 39 | NewMigratePoolJob(), 40 | NewMigrateCStorVolumeJob(), 41 | NewMigrateResourceJob(), 42 | ) 43 | 44 | cmd.PersistentFlags().StringVarP(&options.openebsNamespace, 45 | "openebs-namespace", "", 46 | options.openebsNamespace, 47 | "namespace where openebs components are installed.") 48 | 49 | cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine) 50 | 51 | // Hack: Without the following line, the logs will be prefixed with Error 52 | _ = flag.CommandLine.Parse([]string{}) 53 | 54 | return cmd 55 | } 56 | 57 | // PreRun will check for environement variables to be read and intialized. 58 | func PreRun(cmd *cobra.Command, args []string) { 59 | namespace := util.GetOpenEBSNamespace() 60 | if len(strings.TrimSpace(namespace)) != 0 { 61 | options.openebsNamespace = namespace 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /cmd/migrate/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | mlogger "github.com/openebs/maya/pkg/logs" 21 | "github.com/openebs/upgrade/cmd/migrate/executor" 22 | "github.com/openebs/upgrade/cmd/util" 23 | ) 24 | 25 | func main() { 26 | // Init logging 27 | mlogger.InitLogs() 28 | defer mlogger.FlushLogs() 29 | 30 | err := executor.NewJob().Execute() 31 | util.CheckError(err) 32 | } 33 | -------------------------------------------------------------------------------- /cmd/upgrade/executor/cstor_cspc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "github.com/openebs/maya/pkg/util" 21 | "github.com/spf13/cobra" 22 | "k8s.io/klog/v2" 23 | 24 | "github.com/pkg/errors" 25 | 26 | upgrade "github.com/openebs/upgrade/pkg/upgrade" 27 | "github.com/openebs/upgrade/pkg/version" 28 | ) 29 | 30 | var ( 31 | cstorCSPCUpgradeCmdHelpText = ` 32 | This command upgrades the cStor SPC 33 | 34 | Usage: upgrade cstor-cspc --options... ... 35 | ` 36 | ) 37 | 38 | // NewUpgradeCStorCSPCJob upgrades all the cStor Pools associated with 39 | // a given Storage Pool Claim 40 | func NewUpgradeCStorCSPCJob() *cobra.Command { 41 | cmd := &cobra.Command{ 42 | Use: "cstor-cspc", 43 | Short: "Upgrade cStor CSPC", 44 | Long: cstorCSPCUpgradeCmdHelpText, 45 | Example: `upgrade cstor-cspc ...`, 46 | Run: func(cmd *cobra.Command, args []string) { 47 | if len(args) == 0 { 48 | util.Fatal("failed to upgrade: no cspc name provided") 49 | } 50 | for _, name := range args { 51 | options.resourceKind = "cstorPoolCluster" 52 | util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal) 53 | util.CheckErr(options.InitializeDefaults(cmd), util.Fatal) 54 | util.CheckErr(options.RunCStorCSPCUpgrade(cmd, name), util.Fatal) 55 | } 56 | }, 57 | } 58 | 59 | return cmd 60 | } 61 | 62 | // RunCStorCSPCUpgrade upgrades the given Jiva Volume. 63 | func (u *UpgradeOptions) RunCStorCSPCUpgrade(cmd *cobra.Command, name string) error { 64 | 65 | if version.IsCurrentVersionValid(u.fromVersion) && version.IsDesiredVersionValid(u.toVersion) { 66 | klog.Infof("Upgrading %s to %s", name, u.toVersion) 67 | err := upgrade.Exec(u.fromVersion, u.toVersion, 68 | u.resourceKind, 69 | name, 70 | u.openebsNamespace, 71 | u.imageURLPrefix, 72 | u.toVersionImageTag) 73 | if err != nil { 74 | klog.Error(err) 75 | return errors.Errorf("Failed to upgrade cStor CSPC %v", name) 76 | } 77 | klog.Infof("Successfully upgraded %s to %s", name, u.toVersion) 78 | } else { 79 | return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion) 80 | } 81 | return nil 82 | } 83 | -------------------------------------------------------------------------------- /cmd/upgrade/executor/cstor_volume.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "github.com/openebs/maya/pkg/util" 21 | "github.com/spf13/cobra" 22 | "k8s.io/klog/v2" 23 | 24 | "github.com/pkg/errors" 25 | 26 | upgrade "github.com/openebs/upgrade/pkg/upgrade" 27 | "github.com/openebs/upgrade/pkg/version" 28 | ) 29 | 30 | var ( 31 | cstorCStorVolumeUpgradeCmdHelpText = ` 32 | This command upgrades the cStor SPC 33 | 34 | Usage: upgrade cstor-volume --options... ... 35 | ` 36 | ) 37 | 38 | // NewUpgradeCStorVolumeJob upgrades all the cStor Pools associated with 39 | // a given Storage Pool Claim 40 | func NewUpgradeCStorVolumeJob() *cobra.Command { 41 | cmd := &cobra.Command{ 42 | Use: "cstor-volume", 43 | Short: "Upgrade CStor Volume", 44 | Long: cstorCStorVolumeUpgradeCmdHelpText, 45 | Example: `upgrade cstor-volume ...`, 46 | Run: func(cmd *cobra.Command, args []string) { 47 | if len(args) == 0 { 48 | util.Fatal("failed to upgrade: no volume name provided") 49 | } 50 | for _, name := range args { 51 | options.resourceKind = "cstorVolume" 52 | util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal) 53 | util.CheckErr(options.InitializeDefaults(cmd), util.Fatal) 54 | util.CheckErr(options.RunCStorVolumeUpgrade(cmd, name), util.Fatal) 55 | } 56 | }, 57 | } 58 | 59 | return cmd 60 | } 61 | 62 | // RunCStorVolumeUpgrade upgrades the given Jiva Volume. 63 | func (u *UpgradeOptions) RunCStorVolumeUpgrade(cmd *cobra.Command, name string) error { 64 | 65 | if version.IsCurrentVersionValid(u.fromVersion) && version.IsDesiredVersionValid(u.toVersion) { 66 | klog.Infof("Upgrading %s to %s", name, u.toVersion) 67 | err := upgrade.Exec(u.fromVersion, u.toVersion, 68 | u.resourceKind, 69 | name, 70 | u.openebsNamespace, 71 | u.imageURLPrefix, 72 | u.toVersionImageTag) 73 | if err != nil { 74 | klog.Error(err) 75 | return errors.Errorf("Failed to upgrade CStorVolume %v", name) 76 | } 77 | klog.Infof("Successfully upgraded %s to %s", name, u.toVersion) 78 | } else { 79 | return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion) 80 | } 81 | return nil 82 | } 83 | -------------------------------------------------------------------------------- /cmd/upgrade/executor/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "os" 23 | ) 24 | 25 | // CheckError prints err to stderr and exits with code 1 if err is not nil. Otherwise, it is a 26 | // no-op. 27 | func CheckError(err error) { 28 | if err != nil { 29 | if err != context.Canceled { 30 | fmt.Fprintf(os.Stderr, fmt.Sprintf("An error occurred: %v\n", err)) 31 | } 32 | os.Exit(1) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cmd/upgrade/executor/jiva_volume.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "github.com/openebs/maya/pkg/util" 21 | "github.com/spf13/cobra" 22 | "k8s.io/klog/v2" 23 | 24 | "github.com/pkg/errors" 25 | 26 | upgrade "github.com/openebs/upgrade/pkg/upgrade" 27 | "github.com/openebs/upgrade/pkg/version" 28 | ) 29 | 30 | var ( 31 | jivaVolumeUpgradeCmdHelpText = ` 32 | This command upgrades the jiva volume 33 | 34 | Usage: upgrade jiva-volume --options... ... 35 | ` 36 | ) 37 | 38 | // NewUpgradeJivaVolumeJob upgrades Jiva Volumes 39 | func NewUpgradeJivaVolumeJob() *cobra.Command { 40 | cmd := &cobra.Command{ 41 | Use: "jiva-volume", 42 | Short: "Upgrade Jiva Volume", 43 | Long: jivaVolumeUpgradeCmdHelpText, 44 | Example: `upgrade jiva-volume ...`, 45 | Run: func(cmd *cobra.Command, args []string) { 46 | if len(args) == 0 { 47 | util.Fatal("failed to upgrade: no volume name provided") 48 | } 49 | for _, name := range args { 50 | options.resourceKind = "jivaVolume" 51 | util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal) 52 | util.CheckErr(options.InitializeDefaults(cmd), util.Fatal) 53 | util.CheckErr(options.RunJivaVolumeUpgrade(cmd, name), util.Fatal) 54 | } 55 | }, 56 | } 57 | return cmd 58 | } 59 | 60 | // RunJivaVolumeUpgrade upgrades the given Jiva Volume. 61 | func (u *UpgradeOptions) RunJivaVolumeUpgrade(cmd *cobra.Command, name string) error { 62 | 63 | if version.IsCurrentVersionValid(u.fromVersion) && version.IsDesiredVersionValid(u.toVersion) { 64 | klog.Infof("Upgrading JivaVolume %s to %s", name, u.toVersion) 65 | err := upgrade.Exec(u.fromVersion, u.toVersion, 66 | u.resourceKind, 67 | name, 68 | u.openebsNamespace, 69 | u.imageURLPrefix, 70 | u.toVersionImageTag) 71 | if err != nil { 72 | klog.Error(err) 73 | return errors.Errorf("Failed to upgrade JivaVolume %v", name) 74 | } 75 | klog.Infof("Successfully upgraded %s to %s", name, u.toVersion) 76 | } else { 77 | return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion) 78 | } 79 | return nil 80 | } 81 | -------------------------------------------------------------------------------- /cmd/upgrade/executor/options.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "strings" 21 | 22 | errors "github.com/pkg/errors" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | // UpgradeOptions stores information required for upgrade 28 | type UpgradeOptions struct { 29 | fromVersion string 30 | toVersion string 31 | openebsNamespace string 32 | imageURLPrefix string 33 | toVersionImageTag string 34 | resourceKind string 35 | name string 36 | } 37 | 38 | var ( 39 | options = &UpgradeOptions{ 40 | openebsNamespace: "openebs", 41 | imageURLPrefix: "", 42 | } 43 | ) 44 | 45 | // RunPreFlightChecks will ensure the sanity of the common upgrade options 46 | func (u *UpgradeOptions) RunPreFlightChecks(cmd *cobra.Command) error { 47 | if len(strings.TrimSpace(u.openebsNamespace)) == 0 { 48 | return errors.Errorf("Cannot execute upgrade job: namespace is missing") 49 | } 50 | 51 | if len(strings.TrimSpace(u.fromVersion)) == 0 { 52 | return errors.Errorf("Cannot execute upgrade job: from-version is missing") 53 | } 54 | 55 | if len(strings.TrimSpace(u.toVersion)) == 0 { 56 | return errors.Errorf("Cannot execute upgrade job: to-version is missing") 57 | } 58 | 59 | if len(strings.TrimSpace(u.resourceKind)) == 0 { 60 | return errors.Errorf("Cannot execute upgrade job: resource details are missing") 61 | } 62 | 63 | return nil 64 | } 65 | 66 | // InitializeDefaults will ensure the default values for optional options are 67 | // set. 68 | func (u *UpgradeOptions) InitializeDefaults(cmd *cobra.Command) error { 69 | if len(strings.TrimSpace(u.toVersionImageTag)) == 0 { 70 | u.toVersionImageTag = u.toVersion 71 | } 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /cmd/upgrade/executor/setup_job.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | "flag" 21 | "os" 22 | "strings" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | // NewJob will setup a new upgrade job 28 | func NewJob() *cobra.Command { 29 | // Create a new command. 30 | cmd := &cobra.Command{ 31 | Use: "upgrade", 32 | Short: "OpenEBS Upgrade Utility", 33 | Long: `An utility to upgrade OpenEBS Storage Pools and Volumes, 34 | run as a Kubernetes Job`, 35 | PersistentPreRun: PreRun, 36 | } 37 | 38 | cmd.AddCommand( 39 | NewUpgradeCStorCSPCJob(), 40 | NewUpgradeCStorVolumeJob(), 41 | NewUpgradeResourceJob(), 42 | NewUpgradeJivaVolumeJob(), 43 | ) 44 | 45 | cmd.PersistentFlags().StringVarP(&options.fromVersion, 46 | "from-version", "", 47 | options.fromVersion, 48 | "current version of the resource.") 49 | 50 | cmd.PersistentFlags().StringVarP(&options.toVersion, 51 | "to-version", "", 52 | options.toVersion, 53 | "new version to which resource should be upgraded.") 54 | 55 | cmd.PersistentFlags().StringVarP(&options.openebsNamespace, 56 | "openebs-namespace", "", 57 | options.openebsNamespace, 58 | "namespace where openebs components are installed.") 59 | 60 | cmd.PersistentFlags().StringVarP(&options.imageURLPrefix, 61 | "to-version-image-prefix", "", 62 | options.imageURLPrefix, 63 | "[optional] custom image prefix.") 64 | 65 | cmd.PersistentFlags().StringVarP(&options.toVersionImageTag, 66 | "to-version-image-tag", "", 67 | options.toVersionImageTag, 68 | "[optional] custom image tag. If not specified, to-version will be used") 69 | 70 | cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine) 71 | 72 | // Hack: Without the following line, the logs will be prefixed with Error 73 | _ = flag.CommandLine.Parse([]string{}) 74 | 75 | return cmd 76 | } 77 | 78 | // PreRun will check for environement variables to be read and intialized. 79 | func PreRun(cmd *cobra.Command, args []string) { 80 | namespace := os.Getenv("OPENEBS_NAMESPACE") 81 | if len(strings.TrimSpace(namespace)) != 0 { 82 | options.openebsNamespace = namespace 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /cmd/upgrade/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | mlogger "github.com/openebs/maya/pkg/logs" 21 | "github.com/openebs/upgrade/cmd/upgrade/executor" 22 | ) 23 | 24 | func main() { 25 | // Init logging 26 | mlogger.InitLogs() 27 | defer mlogger.FlushLogs() 28 | 29 | err := executor.NewJob().Execute() 30 | executor.CheckError(err) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/util/env.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package util 18 | 19 | import ( 20 | "os" 21 | ) 22 | 23 | const ( 24 | openebsNamespaceEnv = "OPENEBS_NAMESPACE" 25 | upgradeTaskLabel = "UPGRADE_TASK_LABEL" 26 | ) 27 | 28 | // GetOpenEBSNamespace gets the openebs namespace set to 29 | // the OPENEBS_NAMESPACE env 30 | func GetOpenEBSNamespace() string { 31 | return os.Getenv(openebsNamespaceEnv) 32 | } 33 | 34 | // GetUpgradeTaskLabel gets the upgradeTask label set to 35 | // the UPGRADE_TASK_LABEL env 36 | func GetUpgradeTaskLabel() string { 37 | return os.Getenv(upgradeTaskLabel) 38 | } 39 | -------------------------------------------------------------------------------- /cmd/util/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package util 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "os" 23 | ) 24 | 25 | // CheckError prints err to stderr and exits with code 1 if err is not nil. Otherwise, it is a 26 | // no-op. 27 | func CheckError(err error) { 28 | if err != nil { 29 | if err != context.Canceled { 30 | fmt.Fprintf(os.Stderr, fmt.Sprintf("An error occurred: %v\n", err)) 31 | } 32 | os.Exit(1) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /e2e-tests/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 The OpenEBS Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | FROM ubuntu:18.04 16 | 17 | LABEL maintainer="OpenEBS" 18 | 19 | #Installing necessary ubuntu packages 20 | RUN rm -rf /var/lib/apt/lists/* && \ 21 | apt-get clean && \ 22 | apt-get update --fix-missing || true && \ 23 | apt-get install -y python python-pip netcat iproute2 jq sshpass bc git\ 24 | curl openssh-client 25 | 26 | #Installing ansible 27 | RUN pip install ansible==2.7.3 28 | 29 | RUN pip install ruamel.yaml.clib==0.1.2 30 | 31 | #Installing openshift 32 | RUN pip install openshift==0.11.2 33 | 34 | #Installing jmespath 35 | RUN pip install jmespath 36 | 37 | #Installing Kubectl 38 | ENV KUBE_LATEST_VERSION="v1.20.0" 39 | RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl && \ 40 | chmod +x /usr/local/bin/kubectl 41 | 42 | #Adding hosts entries and making ansible folders 43 | RUN mkdir /etc/ansible/ /ansible && \ 44 | echo "[local]" >> /etc/ansible/hosts && \ 45 | echo "127.0.0.1" >> /etc/ansible/hosts 46 | 47 | #Copying Necessary Files 48 | COPY ./e2e-tests ./e2e-tests 49 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/README.md: -------------------------------------------------------------------------------- 1 | ## Test Case to Migrate the spc non-csi components into cspc csi components 2 | 3 | ## Description 4 | - This test case is capable of Migrating the OpenEBS SPC pool and cStor volume components into CSPC pool and CSI volume 5 | - Before migrating the pool we have to provision the cStor opertor. 6 | - For Migrate the volumes applications need to be scaled down 7 | - This test constitutes the below files. 8 | - cstor-volume-migration-job.j2 - Volume migration job template which has to be populated with the given variables. 9 | - cstor-spc-migration-job.j2 - Pool migration job template which has to be populated with the given variables. 10 | - test_vars.yml - This test_vars file has the list of test specific variables used in E2eBook. 11 | - test.yml - Playbook where the test logic is built to migrate the CSPC CSI components. 12 | - application_scale.yml - This file includes the task to scaledown and scaleup the application. 13 | - This test case should be provided with the parameters in form of job environmental variables in run_e2e_test.yml 14 | 15 | ## E2ebook Environment Variables 16 | 17 | | Parameters | Description | 18 | | ----------------------- | ---------------------------------------------------------- | 19 | | OPERATOR_NS | Namespace where the openebs is deployed | 20 | | Migration_IMAGE_TAG | Image tag for migration job | 21 | | MIGRATE_SPC_POOL | Set the value as `true` to Migrate spc pool | 22 | | MIGRATE_CSTOR_VOLUME | Set the value as `true` to Migrate non-csi volumes | 23 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/application_scale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | ##{{ outer_item }} is name of the pv, the values will passed as a loop variable in test.yml 4 | 5 | - name: Obtain the application namespace to scaledown the application 6 | shell: > 7 | kubectl get pvc --all-namespaces --no-headers | grep {{ outer_item }} | awk '{print $1}' 8 | args: 9 | executable: /bin/bash 10 | register: app_ns 11 | 12 | - name: Obtain the application deployment name to scaledown the application 13 | shell: > 14 | kubectl get deploy -n {{ app_ns.stdout }} --no-headers -o custom-columns=:.metadata.name 15 | args: 16 | executable: /bin/bash 17 | register: app_deploy_name 18 | 19 | - block: 20 | 21 | - name: Obtain the application pod name 22 | shell: > 23 | kubectl get pod -n {{ app_ns.stdout }} -o custom-columns=:.metadata.name --no-headers | grep {{ app_deploy_name.stdout }} 24 | args: 25 | executable: /bin/bash 26 | register: pod_name 27 | 28 | - name: Scaledown the application 29 | shell: > 30 | kubectl scale deploy -n {{ app_ns.stdout }} {{ app_deploy_name.stdout }} --replicas=0 31 | args: 32 | executable: /bin/bash 33 | register: scale_down_status 34 | 35 | - name: Verify if the application scaled down successfully 36 | shell: > 37 | kubectl get deploy -n {{ app_ns.stdout }} {{ app_deploy_name.stdout }} --no-headers -o custom-columns=:.spec.replicas 38 | args: 39 | executable: /bin/bash 40 | register: deploy_status 41 | until: deploy_status.stdout|int == 0 42 | delay: 2 43 | retries: 30 44 | 45 | - name: check if the application pod is deleted 46 | shell: > 47 | kubectl get pod -n {{ app_ns.stdout }} 48 | args: 49 | executable: /bin/bash 50 | register: status 51 | until: '"{{ pod_name.stdout }}" not in status.stdout' 52 | delay: 10 53 | retries: 30 54 | 55 | when: app_status == "scaledown" 56 | 57 | - block: 58 | 59 | - name: Scale the application after migration 60 | shell: > 61 | kubectl scale deploy -n {{ app_ns.stdout }} {{ app_deploy_name.stdout }} --replicas=1 62 | args: 63 | executable: /bin/bash 64 | register: scale_status 65 | 66 | - name: Verify if the application scaled up successfully 67 | shell: > 68 | kubectl get deploy -n {{ app_ns.stdout }} --no-headers -o custom-columns=:.spec.replicas 69 | args: 70 | executable: /bin/bash 71 | register: deploy_rep_status 72 | until: deploy_rep_status.stdout|int == 1 73 | delay: 2 74 | retries: 30 75 | 76 | - name: Obtain the application pod name 77 | shell: > 78 | kubectl get pod -n {{ app_ns.stdout }} -o custom-columns=:.metadata.name --no-headers | grep {{ app_deploy_name.stdout }} 79 | args: 80 | executable: /bin/bash 81 | register: new_pod_name 82 | 83 | - name: check if the application pod is in running state 84 | shell: > 85 | kubectl get pod -n {{ app_ns.stdout }} {{ new_pod_name.stdout }} --no-headers -o custom-columns=:.status.phase 86 | args: 87 | executable: /bin/bash 88 | register: pod_status 89 | until: "'Running' in pod_status.stdout" 90 | delay: 10 91 | retries: 30 92 | 93 | when: app_status == "scaleup" 94 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/cstor-spc-migration-job.j2: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | name: migrate-pool_name 6 | namespace: {{ operator_ns }} 7 | spec: 8 | backoffLimit: 0 9 | template: 10 | spec: 11 | serviceAccountName: service_account 12 | containers: 13 | - name: migrate 14 | args: 15 | - "cstor-spc" 16 | - "--spc-name=pool_name" 17 | - "--v=4" 18 | env: 19 | - name: OPENEBS_NAMESPACE 20 | valueFrom: 21 | fieldRef: 22 | fieldPath: metadata.namespace 23 | tty: true 24 | image: openebs/migrate:{{ migration_image_tag }} 25 | restartPolicy: Never 26 | --- 27 | 28 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/cstor-volume-migration-job.j2: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | name: migrate-cstor-cstor_volume_name 6 | namespace: {{ operator_ns }} 7 | spec: 8 | backoffLimit: 4 9 | template: 10 | spec: 11 | serviceAccountName: service_account 12 | containers: 13 | - name: migrate 14 | args: 15 | - "cstor-volume" 16 | - "--pv-name=cstor_volume_name" 17 | - "--v=4" 18 | env: 19 | - name: OPENEBS_NAMESPACE 20 | valueFrom: 21 | fieldRef: 22 | fieldPath: metadata.namespace 23 | tty: true 24 | image: openebs/migrate:{{ migration_image_tag }} 25 | restartPolicy: Never 26 | --- 27 | 28 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/cstor_replica_version_check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Obtain the CVR name to verify the current version 3 | shell: > 4 | kubectl get cvr -n {{ operator_ns }} -l openebs.io/persistent-volume={{ outer_item }} 5 | -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 6 | register: cvr_name 7 | failed_when: 'cvr_name.stdout == ""' 8 | 9 | - name: Check if the CVRs are upgraded to newer version 10 | shell: > 11 | kubectl get cvr -n {{ operator_ns }} {{ item }} 12 | -o custom-columns=:.versionDetails.status.current --no-headers 13 | register: cvr_version 14 | failed_when: "cvr_version.stdout != operator_image_tag" 15 | with_items: 16 | - "{{ cvr_name.stdout_lines }}" 17 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/run_e2e_test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | generateName: cstor-cspc-csi-migration- 6 | namespace: e2e 7 | spec: 8 | template: 9 | metadata: 10 | name: e2e 11 | labels: 12 | app: cspc-csi-migration 13 | spec: 14 | serviceAccountName: e2e 15 | restartPolicy: Never 16 | containers: 17 | - name: ansibletest 18 | image: openebs/upgrade-e2e:ci 19 | imagePullPolicy: IfNotPresent 20 | 21 | env: 22 | - name: ANSIBLE_STDOUT_CALLBACK 23 | #value: log_plays, actionable, default 24 | value: default 25 | 26 | # Namespace where OpenEBS is deployed 27 | - name: OPERATOR_NS 28 | value: "" 29 | 30 | # Image tag for operator version 31 | - name: OPERATOR_IMAGE_TAG 32 | value: "" 33 | 34 | # Image tag for migration Job 35 | - name: MIGRATATION_IMAGE_TAG 36 | value: "" 37 | 38 | # set to "true" if you want to upgrade cStor CSPC pool 39 | - name: MIGRATE_SPC_POOL 40 | value: "" 41 | 42 | # set to "true" if you want to upgrade CSI volumes 43 | - name: MIGRATE_CSTOR_VOLUME 44 | value: "" 45 | 46 | command: ["/bin/bash"] 47 | args: ["-c", "ansible-playbook ./e2e-tests/experiments/cspc_csi_migration/test.yml -i /etc/ansible/hosts -v; exit 0"] 48 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_migration/test_vars.yml: -------------------------------------------------------------------------------- 1 | # Test-specific parameters 2 | operator_ns: "{{ lookup('env','OPERATOR_NS') }}" 3 | test_name: cstor-cspc-csi-migration 4 | migration_image_tag: "{{ lookup('env', 'MIGRATATION_IMAGE_TAG') }}" 5 | operator_image_tag: "{{ lookup('env', 'OPERATOR_IMAGE_TAG') }}" 6 | spc_pool_migration: "{{ lookup('env', 'MIGRATE_SPC_POOL') }}" 7 | cstor_volume_migration: "{{ lookup('env', 'MIGRATE_CSTOR_VOLUME') }}" 8 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_upgrade/README.md: -------------------------------------------------------------------------------- 1 | ## Test Case to upgrade the cspc csi components 2 | 3 | ## Description 4 | - This test case is capable of upgrading the OpenEBS CSPC pool and cStor-csi volume components. 5 | - First it will verify the CSPC CSI components version to upgrade. 6 | - This test case upgrades the cstor operator, csi provisioner , cspc pool and csi volumes 7 | into new desired version. And verify the status of each components. 8 | - This test constitutes the below files. 9 | - cstor-csi-volume-upgrade-job.j2 - CSI volume upgrade job template which has to be populated with the given variables. 10 | - cstor-cspc-upgrade-job.j2 - CSPC pool upgrade job template which has to be populated with the given variables. 11 | - test_vars.yml - This test_vars file has the list of test specific variables used in E2eBook. 12 | - test.yml - Playbook where the test logic is built to Upgrade the CSPC CSI components. 13 | - cstor_replica_version_check.yml - This file includes the task to check the cstor volume replicas are upgraded to desired version. 14 | - This test case should be provided with the parameters in form of job environmental variables in run_e2e_test.yml 15 | 16 | ## E2ebook Environment Variables 17 | 18 | | Parameters | Description | 19 | | ----------------------- | ---------------------------------------------------------- | 20 | | FROM_VERSION | Old version which needs to be upgraded | 21 | | TO_VERSION | New version to upgrade | 22 | | OPERATOR_NS | Namespace where the openebs is deployed | 23 | | UPGRADE_IMAGE_TAG | Image tag for upgrade job | 24 | | CSPC_POOL_UPGRADE | Set the value as `true` to Upgrade cspc pool | 25 | | CSPC_VOLUME_UPGRADE | Set the value as `true` to Upgrade csi volumes | 26 | | CSTOR_OPERATOR_UPGRADE | Set the value as `true` to upgrade the cstor opertor and csi provisioner | 27 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_upgrade/cstor-csi-volume-upgrade-job.j2: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | name: cstor-csi-volume-upgrade 6 | namespace: {{ operator_ns }} 7 | spec: 8 | backoffLimit: 4 9 | template: 10 | spec: 11 | serviceAccountName: service_account 12 | containers: 13 | - name: upgrade 14 | args: 15 | - "cstor-volume" 16 | - "--from-version={{ from_version }}" 17 | - "--to-version={{ to_version}}" 18 | - "--v=4" 19 | env: 20 | - name: OPENEBS_NAMESPACE 21 | valueFrom: 22 | fieldRef: 23 | fieldPath: metadata.namespace 24 | tty: true 25 | image: openebs/upgrade:{{ upgrade_image_tag }} 26 | imagePullPolicy: IfNotPresent 27 | restartPolicy: OnFailure 28 | --- 29 | 30 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_upgrade/cstor-cspc-upgrade-job.j2: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | name: cstor-cspc-upgrade 6 | namespace: {{ operator_ns }} 7 | spec: 8 | backoffLimit: 4 9 | template: 10 | spec: 11 | serviceAccountName: service_account 12 | containers: 13 | - name: upgrade 14 | args: 15 | - "cstor-cspc" 16 | - "--from-version={{ from_version }}" 17 | - "--to-version={{ to_version }}" 18 | - "--v=4" 19 | # DO NOT CHANGE BELOW PARAMETERS 20 | env: 21 | - name: OPENEBS_NAMESPACE 22 | valueFrom: 23 | fieldRef: 24 | fieldPath: metadata.namespace 25 | tty: true 26 | image: openebs/upgrade:{{ upgrade_image_tag }} 27 | imagePullPolicy: IfNotPresent 28 | restartPolicy: OnFailure 29 | --- 30 | 31 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_upgrade/cstor_replica_version_check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Obtain the CVR name to verify the current version 3 | shell: > 4 | kubectl get cvr -n {{ operator_ns }} -l openebs.io/persistent-volume={{ outer_item }} 5 | -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 6 | register: cvr_name 7 | failed_when: 'cvr_name.stdout == ""' 8 | 9 | - name: Check if the CVRs are upgraded to newer version 10 | shell: > 11 | kubectl get cvr -n {{ operator_ns }} {{ item }} 12 | -o custom-columns=:.versionDetails.status.current --no-headers 13 | register: cvr_version 14 | failed_when: "cvr_version.stdout != to_version" 15 | with_items: 16 | - "{{ cvr_name.stdout_lines }}" 17 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_upgrade/run_e2e_test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | generateName: cstor-csi-upgrade- 6 | namespace: e2e 7 | spec: 8 | template: 9 | metadata: 10 | name: e2e 11 | labels: 12 | app: cstor-csi-upgrade 13 | spec: 14 | serviceAccountName: e2e 15 | restartPolicy: Never 16 | containers: 17 | - name: ansibletest 18 | image: openebs/upgrade-e2e:ci 19 | imagePullPolicy: IfNotPresent 20 | 21 | env: 22 | - name: ANSIBLE_STDOUT_CALLBACK 23 | value: default 24 | 25 | # OpenEBS Version already installed 26 | - name: FROM_VERSION 27 | value: "" 28 | 29 | # OpenEBS version to be Upgraded 30 | - name: TO_VERSION 31 | value: "" 32 | 33 | - name: RELEASE_VERSION 34 | value: "" 35 | 36 | # Namespace where OpenEBS is deployed 37 | - name: OPERATOR_NS 38 | value: "openebs" 39 | 40 | # Image tag for Upgrade Job 41 | - name: UPGRADE_IMAGE_TAG 42 | value: "" 43 | 44 | # set to "true" if you want to upgrade cStor CSPC pool 45 | - name: CSPC_POOL_UPGRADE 46 | value: "" 47 | 48 | # set to "true" if you want to upgrade CSI volumes 49 | - name: CSI_VOLUME_UPGRADE 50 | value: "" 51 | 52 | # set to "true" to upgrade CSTOR OPERATOR plane 53 | - name: CSTOR_OPERATOR_UPGRADE 54 | value: "" 55 | 56 | - name: COMMIT_ID 57 | value: "" 58 | 59 | - name: RC_TAG 60 | value: "" 61 | 62 | command: ["/bin/bash"] 63 | args: ["-c", "ansible-playbook ./e2e-tests/experiments/cspc_csi_upgrade/test.yml -i /etc/ansible/hosts -v; exit 0"] 64 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cspc_csi_upgrade/test_vars.yml: -------------------------------------------------------------------------------- 1 | # Test-specific parameters 2 | operator_ns: "{{ lookup('env','OPERATOR_NS') }}" 3 | test_name: cstor-csi-upgrade 4 | from_version: "{{ lookup('env','FROM_VERSION') }}" 5 | to_version: "{{ lookup('env','TO_VERSION') }}" 6 | upgrade_image_tag: "{{ lookup('env', 'UPGRADE_IMAGE_TAG') }}" 7 | cstor_operator: cstor-operator.yaml 8 | cstor_operator_link: https://raw.githubusercontent.com/openebs/charts/gh-pages/versioned/{{ release_branch }}/cstor-operator.yaml 9 | release_operator_link: "https://raw.githubusercontent.com/openebs/charts/{{ lookup('env','COMMIT_ID') }}/versioned/{{ release_branch }}/cstor-operator.yaml" 10 | rc_operator_link: "https://raw.githubusercontent.com/openebs/charts/{{ lookup('env','COMMIT_ID') }}/versioned/{{ release_branch }}/cstor-operator-{{ lookup('env','RC_TAG') }}.yaml" 11 | cspc_pool_upgrade: "{{ lookup('env', 'CSPC_POOL_UPGRADE') }}" 12 | csi_volume_upgrade: "{{ lookup('env', 'CSI_VOLUME_UPGRADE') }}" 13 | cstor_operator_upgrade: "{{ lookup('env', 'CSTOR_OPERATOR_UPGRADE') }}" 14 | commit_id: "{{ lookup('env','COMMIT_ID') }}" 15 | rc_tag: "{{ lookup('env','RC_TAG') }}" 16 | release_branch: "{{ lookup('env','RELEASE_VERSION') }}" 17 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cstor-operator-provision/README.md: -------------------------------------------------------------------------------- 1 | # Test Case to deploy the OpenEBS cStor operator. 2 | 3 | ## Description 4 | - This test case is capable of setting up OpenEBS cStor cspc,cvc operator and OpenEBS CSI control plane components 5 | 6 | - This test constitutes the below files. 7 | 8 | ### run_e2e_test.yml 9 | - This includes the e2e job which triggers the test execution. The pod includes several environmental variables such as 10 | - RELEASE_VERSION: Version Tag for the cstor operator 11 | - ACTION: Values should be provision for deploy, to remove the operator value should be deprovision. 12 | - WEBHOOK_FAILURE_POLICY: value for the webhook failure policy. 13 | 14 | ### test_vars.yml 15 | - This test_vars file has the list of test specific variables used in E2E test. 16 | 17 | ### test.yml 18 | - test.yml is the playbook where the test logic is built to deploy OpenEBS cStor CSPC, CVC operator and OpenEBS CSI control plane components. 19 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cstor-operator-provision/run_e2e_test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | generateName: e2e-cstor-operator- 6 | namespace: e2e 7 | spec: 8 | template: 9 | metadata: 10 | name: e2e 11 | labels: 12 | provider: cstor-operator 13 | spec: 14 | serviceAccountName: e2e 15 | restartPolicy: Never 16 | containers: 17 | - name: ansibletest 18 | image: openebs/upgrade-e2e:ci 19 | imagePullPolicy: IfNotPresent 20 | env: 21 | - name: ANSIBLE_STDOUT_CALLBACK 22 | value: default 23 | 24 | - name: OPENEBS_VERSION 25 | value: "" 26 | 27 | - name: ACTION 28 | value: provision 29 | 30 | ## Admission server policy 31 | #supported values are 'fail' or 'ignore' 32 | - name: WEBHOOK_FAILURE_POLICY 33 | value: "ignore" 34 | 35 | - name: CSI_NS 36 | value: "openebs" 37 | 38 | - name: COMMIT_ID 39 | value: "" 40 | 41 | - name: RC_TAG 42 | value: "" 43 | 44 | command: ["/bin/bash"] 45 | args: ["-c", "ansible-playbook ./e2e-tests/experiments/cstor-operator-provision/test.yml -i /etc/ansible/hosts -vv; exit 0"] 46 | -------------------------------------------------------------------------------- /e2e-tests/experiments/cstor-operator-provision/test_vars.yml: -------------------------------------------------------------------------------- 1 | cstor_operator_link: https://raw.githubusercontent.com/openebs/charts/gh-pages/versioned/{{ openebs_version }}/cstor-operator.yaml 2 | release_operator_link: "https://raw.githubusercontent.com/openebs/charts/{{ commit_id }}/versioned/{{ openebs_version }}/cstor-operator.yaml" 3 | rc_operator_link: "https://raw.githubusercontent.com/openebs/charts/{{ commit_id }}/versioned/{{ openebs_version }}/cstor-operator-{{ rc_tag }}.yaml" 4 | cstor_operator: cstor-operator.yaml 5 | openebs_version: "{{ lookup('env','OPENEBS_VERSION') }}" 6 | webhook_policy: "{{ lookup('env','WEBHOOK_FAILURE_POLICY') }}" 7 | test_name: "openebs-cstor-operator-{{ lookup('env','ACTION') }}" 8 | operator_ns: "{{ lookup('env','CSI_NS') }}" 9 | commit_id: "{{ lookup('env','COMMIT_ID') }}" 10 | rc_tag: "{{ lookup('env','RC_TAG') }}" 11 | -------------------------------------------------------------------------------- /e2e-tests/experiments/openebs-provision/helm_provision.yml: -------------------------------------------------------------------------------- 1 | - name: Install helm client 2 | shell: curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash 3 | args: 4 | executable: /bin/bash 5 | register: output 6 | until: "'installed' in output.stdout" 7 | delay: 30 8 | retries: 5 9 | 10 | - name: Installing openebs using stable charts. 11 | shell: > 12 | helm install --namespace {{ namespace }} --name openebs stable/openebs --version {{ openebs_version }} 13 | args: 14 | executable: /bin/bash 15 | register: openebs_out 16 | until: "'The OpenEBS has been installed' in openebs_out.stdout" 17 | delay: 5 18 | retries: 5 19 | -------------------------------------------------------------------------------- /e2e-tests/experiments/openebs-provision/operator_provision.yml: -------------------------------------------------------------------------------- 1 | ## Obtaining the OpenEBS operator from charts. 2 | ## If the chart is not created, openebs operator will be downloaded from master branch. 3 | 4 | - block: 5 | 6 | - name: Downloading openebs operator yaml for rc tag 7 | get_url: 8 | url: "{{ release_operator_link }}" 9 | dest: "{{ playbook_dir }}/{{ openebs_operator }}" 10 | force: yes 11 | register: release_operator 12 | when: rc_tag == "" 13 | 14 | - name: Downloading openebs operator yaml for rc tag 15 | get_url: 16 | url: "{{ rc_operator_link }}" 17 | dest: "{{ playbook_dir }}/{{ openebs_operator }}" 18 | force: yes 19 | register: rc_operator 20 | when: rc_tag != "" 21 | 22 | when: 23 | - commit_id != "charts" 24 | 25 | - name: Downloading openebs operator yaml for rc tag 26 | get_url: 27 | url: "{{ new_operator }}" 28 | dest: "{{ playbook_dir }}/{{ openebs_operator }}" 29 | force: yes 30 | register: rc_operator 31 | when: 32 | - commit_id == "charts" 33 | 34 | - name: Change the openebs analytics value of openebs resources in operator YAML 35 | replace: 36 | path: "{{ openebs_operator }}" 37 | regexp: 'value: "true"' 38 | after: '- name: OPENEBS_IO_ENABLE_ANALYTICS' 39 | replace: 'value: "false"' 40 | 41 | - name: Change the value of sparse file count in operator YAML 42 | replace: 43 | path: "{{ openebs_operator }}" 44 | regexp: 'value: "0"' 45 | after: '- name: SPARSE_FILE_COUNT' 46 | replace: 'value: "{{ sparse_file_count }}"' 47 | 48 | - name: Applying openebs operator 49 | shell: kubectl apply -f "{{ openebs_operator }}" 50 | args: 51 | executable: /bin/bash 52 | when: namespace == "openebs" 53 | 54 | - block: 55 | 56 | - name: Change the default namespace in openebs operator spec 57 | replace: 58 | path: "{{ openebs_operator }}" 59 | regexp: 'namespace: openebs' 60 | replace: 'namespace: "{{ namespace }}"' 61 | 62 | - name: Create the namesapce to deploy openebs 63 | shell: kubectl create namespace {{ namespace }} 64 | args: 65 | executable: /bin/bash 66 | 67 | - name: Applying openebs operator 68 | shell: kubectl apply -f "{{ openebs_operator }}" 69 | args: 70 | executable: /bin/bash 71 | 72 | when: namespace != "openebs" 73 | -------------------------------------------------------------------------------- /e2e-tests/experiments/openebs-provision/run_e2e_test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: batch/v1 3 | kind: Job 4 | metadata: 5 | name: e2e-openebs-runner 6 | namespace: e2e 7 | spec: 8 | template: 9 | metadata: 10 | name: e2e 11 | labels: 12 | provider: openebs-runner 13 | spec: 14 | serviceAccountName: e2e 15 | restartPolicy: Never 16 | containers: 17 | - name: ansibletest 18 | image: openebs/upgrade-e2e:ci 19 | imagePullPolicy: IfNotPresent 20 | env: 21 | - name: ANSIBLE_STDOUT_CALLBACK 22 | value: default 23 | 24 | - name: OPENEBS_VERSION 25 | value: "" 26 | 27 | - name: SPARSE_FILE_COUNT 28 | value: "10" 29 | 30 | - name: DEPLOY_MODE 31 | value: "operator" 32 | 33 | - name: Action 34 | value: provision 35 | 36 | - name: OPERATOR_NS 37 | value: "openebs" 38 | 39 | - name: COMMIT_ID 40 | value: "" 41 | 42 | - name: RC_TAG 43 | value: "" 44 | 45 | command: ["/bin/bash"] 46 | args: ["-c", "ansible-playbook ./e2e-tests/experiments/openebs-provision/test.yml -i /etc/ansible/hosts -vv; exit 0"] 47 | -------------------------------------------------------------------------------- /e2e-tests/experiments/openebs-provision/test_vars.yml: -------------------------------------------------------------------------------- 1 | #kubeapply: kubectl --kubeconfig /root/admin.conf 2 | new_operator: "https://raw.githubusercontent.com/openebs/charts/gh-pages/versioned/{{ lookup('env','OPENEBS_VERSION') }}/openebs-operator.yaml" 3 | rc_operator_link: "https://raw.githubusercontent.com/openebs/charts/{{ lookup('env','COMMIT_ID') }}/versioned/{{ lookup('env','OPENEBS_VERSION') }}/openebs-operator-{{ lookup('env','RC_TAG') }}.yaml" 4 | release_operator_link: "https://raw.githubusercontent.com/openebs/charts/{{ lookup('env','COMMIT_ID') }}/versioned/{{ lookup('env','OPENEBS_VERSION') }}/openebs-operator.yaml" 5 | openebs_version: "{{ lookup('env','OPENEBS_VERSION') }}" 6 | openebs_operator: openebs-operator.yaml 7 | test_name: "openebs-{{ lookup('env','Action') }}" 8 | deploy_type: "{{ lookup('env','DEPLOY_MODE') }}" 9 | namespace: "{{ lookup('env','OPERATOR_NS') }}" 10 | sparse_file_count: "{{ lookup('env','SPARSE_FILE_COUNT') }}" 11 | commit_id: "{{ lookup('env','COMMIT_ID') }}" 12 | rc_tag: "{{ lookup('env','RC_TAG') }}" 13 | -------------------------------------------------------------------------------- /e2e-tests/hack/crds.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The OpenEBS Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --- 15 | apiVersion: apiextensions.k8s.io/v1 16 | kind: CustomResourceDefinition 17 | metadata: 18 | annotations: 19 | controller-gen.kubebuilder.io/version: v0.4.0 20 | creationTimestamp: null 21 | name: e2eresults.e2e.io 22 | spec: 23 | group: e2e.io 24 | names: 25 | kind: E2eResult 26 | listKind: E2eResultList 27 | plural: e2eresults 28 | shortNames: 29 | - e2er 30 | singular: e2eresult 31 | scope: Cluster 32 | versions: 33 | - name: v1alpha1 34 | schema: 35 | openAPIV3Schema: 36 | description: E2eResult represents an e2e result 37 | properties: 38 | apiVersion: 39 | description: 'APIVersion defines the versioned schema of this representation 40 | of an object. Servers should convert recognized schemas to the latest 41 | internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' 42 | type: string 43 | kind: 44 | description: 'Kind is a string value representing the REST resource this 45 | object represents. Servers may infer this from the endpoint the client 46 | submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' 47 | type: string 48 | metadata: 49 | type: object 50 | spec: 51 | description: Spec i.e. specifications of the E2eResult 52 | properties: 53 | testMetadata: 54 | description: TestMetadata holds information on the testcase 55 | properties: 56 | app: 57 | description: App is the name of the application running 58 | nullable: true 59 | type: string 60 | chaostype: 61 | description: Chaostype is the type of test case 62 | nullable: true 63 | type: string 64 | type: object 65 | testStatus: 66 | description: TestStatus holds the state of testcase, manually updated 67 | by json merge patch result is the useful value today, but anticipate 68 | phase use in future 69 | properties: 70 | phase: 71 | description: Phase tells whether the test case is running or completed 72 | nullable: true 73 | type: string 74 | result: 75 | description: Result tells whether the test case passed or failed 76 | nullable: true 77 | type: string 78 | type: object 79 | type: object 80 | status: 81 | description: Status of E2eResult 82 | type: object 83 | type: object 84 | served: true 85 | storage: true 86 | status: 87 | acceptedNames: 88 | kind: "" 89 | plural: "" 90 | conditions: [] 91 | storedVersions: [] 92 | -------------------------------------------------------------------------------- /e2e-tests/hack/e2e-result.j2: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: e2e.io/v1alpha1 3 | kind: E2eResult 4 | metadata: 5 | 6 | # name of the e2e testcase 7 | name: {{ test }} 8 | spec: 9 | 10 | # holds information on the testcase 11 | testMetadata: 12 | app: {{ app }} 13 | chaostype: {{ chaostype }} 14 | 15 | # holds the state of testcase, manually updated by json merge patch 16 | # result is the useful value today, but anticipate phase use in future 17 | testStatus: 18 | phase: {{ phase }} 19 | result: {{ verdict }} 20 | 21 | -------------------------------------------------------------------------------- /e2e-tests/hack/push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2021 The OpenEBS Authors. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -e 17 | 18 | if [ -z "${REPONAME}" ] 19 | then 20 | REPONAME="openebs" 21 | fi 22 | 23 | if [ -z "${IMGNAME}" ] || [ -z "${IMGTAG}" ]; 24 | then 25 | echo "Image details are missing. Nothing to push."; 26 | exit 1 27 | fi 28 | 29 | IMAGEID=$( sudo docker images -q ${REPONAME}/${IMGNAME}:${IMGTAG} ) 30 | 31 | if [ ! -z "${DNAME}" ] && [ ! -z "${DPASS}" ]; 32 | then 33 | sudo docker login -u "${DNAME}" -p "${DPASS}"; 34 | # Push image to docker hub 35 | echo "Pushing ${REPONAME}/${IMGNAME}:${IMGTAG} ..."; 36 | sudo docker push ${REPONAME}/${IMGNAME}:${IMGTAG} ; 37 | if [ ! -z "${TRAVIS_TAG}" ] ; 38 | then 39 | # Push with different tags if tagged as a release 40 | # When github is tagged with a release, then Travis will 41 | # set the release tag in env TRAVIS_TAG 42 | echo "Pushing ${REPONAME}/${IMGNAME}:${TRAVIS_TAG} ..."; 43 | sudo docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:${TRAVIS_TAG} 44 | sudo docker push ${REPONAME}/${IMGNAME}:${TRAVIS_TAG}; 45 | echo "Pushing ${REPONAME}/${IMGNAME}:latest ..."; 46 | sudo docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:latest 47 | sudo docker push ${REPONAME}/${IMGNAME}:latest; 48 | fi; 49 | else 50 | echo "No docker credentials provided. Skip uploading ${REPONAME}/${IMGNAME}:${IMGTAG} to docker hub"; 51 | fi; 52 | -------------------------------------------------------------------------------- /e2e-tests/hack/rbac.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The OpenEBS Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | apiVersion: v1 16 | kind: Namespace 17 | metadata: 18 | name: e2e 19 | --- 20 | apiVersion: v1 21 | kind: ServiceAccount 22 | metadata: 23 | name: e2e 24 | namespace: e2e 25 | labels: 26 | name: e2e 27 | --- 28 | # Source: openebs/templates/clusterrole.yaml 29 | apiVersion: rbac.authorization.k8s.io/v1 30 | kind: ClusterRole 31 | metadata: 32 | name: e2e 33 | labels: 34 | name: e2e 35 | rules: 36 | - apiGroups: ["*"] 37 | resources: ["*"] 38 | verbs: ["*"] 39 | --- 40 | apiVersion: rbac.authorization.k8s.io/v1 41 | kind: ClusterRoleBinding 42 | metadata: 43 | name: e2e 44 | labels: 45 | name: e2e 46 | roleRef: 47 | apiGroup: rbac.authorization.k8s.io 48 | kind: ClusterRole 49 | name: e2e 50 | subjects: 51 | - kind: ServiceAccount 52 | name: e2e 53 | namespace: e2e 54 | -------------------------------------------------------------------------------- /e2e-tests/utils/create_testname.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - block: 3 | - name: Record test instance/run ID 4 | set_fact: 5 | run_id: "{{ lookup('env','RUN_ID') }}" 6 | 7 | - name: Construct testname appended with runID 8 | set_fact: 9 | test_name: "{{ test_name }}-{{ run_id }}" 10 | 11 | when: lookup('env','RUN_ID') 12 | -------------------------------------------------------------------------------- /e2e-tests/utils/update_e2e_result_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - block: 3 | - name: Generate the e2e result CR to reflect SOT (Start of Test) 4 | template: 5 | src: /e2e-tests/hack/e2e-result.j2 6 | dest: e2e-result.yaml 7 | vars: 8 | test: "{{ test_name }}" 9 | app: "" 10 | chaostype: "" 11 | phase: in-progress 12 | verdict: none 13 | 14 | - name: Analyze the cr yaml 15 | shell: cat e2e-result.yaml 16 | 17 | - name: Apply the e2e result CR 18 | shell: kubectl apply -f e2e-result.yaml 19 | args: 20 | executable: /bin/bash 21 | register: lr_status 22 | failed_when: "lr_status is failed" 23 | 24 | when: status == "SOT" 25 | 26 | - block: 27 | - name: Generate the e2e result CR to reflect EOT (End of Test) 28 | template: 29 | src: /e2e-tests/hack/e2e-result.j2 30 | dest: e2e-result.yaml 31 | vars: 32 | test: "{{ test_name }}" 33 | app: "" 34 | chaostype: "" 35 | phase: completed 36 | verdict: "{{ flag }}" 37 | 38 | - name: Analyze the cr yaml 39 | shell: cat e2e-result.yaml 40 | 41 | - name: Apply the e2e result CR 42 | shell: kubectl apply -f e2e-result.yaml 43 | args: 44 | executable: /bin/bash 45 | register: lr_status 46 | failed_when: "lr_status is failed" 47 | 48 | when: status == "EOT" 49 | -------------------------------------------------------------------------------- /examples/migrate/cstor-volume-migration.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | apiVersion: batch/v1 17 | kind: Job 18 | metadata: 19 | # the name can be of the form migrate-cstor- 20 | name: migrate-cstor-pvc-dd6ad226-c2b3-47c8-a8bf-46cb820d187a 21 | namespace: openebs 22 | spec: 23 | backoffLimit: 4 24 | template: 25 | spec: 26 | #VERIFY the value of serviceAccountName is pointing to service account 27 | # created within openebs namespace. Use the non-default account. 28 | # by running `kubectl get sa -n ` 29 | serviceAccountName: openebs-maya-operator 30 | containers: 31 | - name: migrate 32 | args: 33 | - "cstor-volume" 34 | # name of the pv that is to be migrated 35 | - "--pv-name=pvc-dd6ad226-c2b3-47c8-a8bf-46cb820d187a" 36 | 37 | #Following are optional parameters 38 | #Log Level 39 | - "--v=4" 40 | #DO NOT CHANGE BELOW PARAMETERS 41 | env: 42 | - name: OPENEBS_NAMESPACE 43 | valueFrom: 44 | fieldRef: 45 | fieldPath: metadata.namespace 46 | tty: true 47 | # the version of the image should be same the 48 | # version of cstor-operator installed. 49 | image: openebs/migrate: 50 | restartPolicy: Never 51 | --- 52 | 53 | -------------------------------------------------------------------------------- /examples/migrate/spc-migration.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | apiVersion: batch/v1 17 | kind: Job 18 | metadata: 19 | # the name can be of the form migrate- 20 | name: migrate-spc-sparse-claim 21 | namespace: openebs 22 | spec: 23 | backoffLimit: 4 24 | template: 25 | spec: 26 | #VERIFY the value of serviceAccountName is pointing to service account 27 | # created within openebs namespace. Use the non-default account. 28 | # by running `kubectl get sa -n ` 29 | serviceAccountName: openebs-maya-operator 30 | containers: 31 | - name: migrate 32 | args: 33 | - "cstor-spc" 34 | # name of the spc that is to be migrated 35 | - "--spc-name=sparse-claim" 36 | # optional flag to rename the spc to a specific name 37 | # - "--cspc-name=sparse-claim-migrated" 38 | 39 | #Following are optional parameters 40 | #Log Level 41 | - "--v=4" 42 | #DO NOT CHANGE BELOW PARAMETERS 43 | env: 44 | - name: OPENEBS_NAMESPACE 45 | valueFrom: 46 | fieldRef: 47 | fieldPath: metadata.namespace 48 | tty: true 49 | # the version of the image should be same the 50 | # version of cstor-operator installed. 51 | image: openebs/migrate: 52 | restartPolicy: Never 53 | --- 54 | 55 | -------------------------------------------------------------------------------- /examples/upgrade/cstor-cspc.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This is an example YAML for upgrading cstor CSPC. 16 | # Some of the values below needs to be changed to 17 | # match your openebs installation. The fields are 18 | # indicated with VERIFY 19 | --- 20 | apiVersion: batch/v1 21 | kind: Job 22 | metadata: 23 | # VERIFY that you have provided a unique name for this upgrade job. 24 | # The name can be any valid K8s string for name. 25 | name: cstor-cspc-upgrade 26 | 27 | # VERIFY the value of namespace is same as the namespace where openebs components 28 | # are installed. You can verify using the command: 29 | # `kubectl get pods -n -l openebs.io/component-name=maya-apiserver` 30 | # The above command should return status of the openebs-apiserver. 31 | namespace: openebs 32 | spec: 33 | backoffLimit: 4 34 | template: 35 | spec: 36 | # VERIFY the value of serviceAccountName is pointing to service account 37 | # created within openebs namespace. Use the non-default account. 38 | # by running `kubectl get sa -n ` 39 | serviceAccountName: openebs-maya-operator 40 | containers: 41 | - name: upgrade 42 | args: 43 | - "cstor-cspc" 44 | 45 | # --from-version is the current version of the pool 46 | - "--from-version=1.11.0" 47 | 48 | # --to-version is the version desired upgrade version 49 | - "--to-version=1.12.0" 50 | # if required the image prefix of the pool deployments can be 51 | # changed using the flag below, defaults to whatever was present on old 52 | # deployments. 53 | #- "--to-version-image-prefix=openebs/" 54 | # if required the image tags for pool deployments can be changed 55 | # to a custom image tag using the flag below, 56 | # defaults to the --to-version mentioned above. 57 | #- "--to-version-image-tag=ci" 58 | 59 | # VERIFY that you have provided the correct list of CSPC Names 60 | - "cspc-stripe" 61 | 62 | # Following are optional parameters 63 | # Log Level 64 | - "--v=4" 65 | # DO NOT CHANGE BELOW PARAMETERS 66 | env: 67 | - name: OPENEBS_NAMESPACE 68 | valueFrom: 69 | fieldRef: 70 | fieldPath: metadata.namespace 71 | tty: true 72 | 73 | # the image version should be same as the --to-version mentioned above 74 | # in the args of the job 75 | image: openebs/upgrade: 76 | imagePullPolicy: IfNotPresent 77 | restartPolicy: OnFailure 78 | --- 79 | 80 | -------------------------------------------------------------------------------- /examples/upgrade/cstor-volume.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This is an example YAML for upgrading cstor volume. 16 | # Some of the values below needs to be changed to 17 | # match your openebs installation. The fields are 18 | # indicated with VERIFY 19 | --- 20 | apiVersion: batch/v1 21 | kind: Job 22 | metadata: 23 | # VERIFY that you have provided a unique name for this upgrade job. 24 | # The name can be any valid K8s string for name. 25 | name: cstor-volume-upgrade 26 | 27 | # VERIFY the value of namespace is same as the namespace where openebs components 28 | # are installed. You can verify using the command: 29 | # `kubectl get pods -n -l openebs.io/component-name=maya-apiserver` 30 | # The above command should return status of the openebs-apiserver. 31 | namespace: openebs 32 | spec: 33 | backoffLimit: 4 34 | template: 35 | spec: 36 | # VERIFY the value of serviceAccountName is pointing to service account 37 | # created within openebs namespace. Use the non-default account. 38 | # by running `kubectl get sa -n ` 39 | serviceAccountName: openebs-maya-operator 40 | containers: 41 | - name: upgrade 42 | args: 43 | - "cstor-volume" 44 | 45 | # --from-version is the current version of the volume 46 | - "--from-version=1.11.0" 47 | 48 | # --to-version is the version desired upgrade version 49 | - "--to-version=1.12.0" 50 | # if required the image prefix of the volume deployments can be 51 | # changed using the flag below, defaults to whatever was present on old 52 | # deployments. 53 | #- "--to-version-image-prefix=openebs/" 54 | # if required the image tags for volume deployments can be changed 55 | # to a custom image tag using the flag below, 56 | # defaults to the --to-version mentioned above. 57 | #- "--to-version-image-tag=ci" 58 | 59 | # VERIFY that you have provided the correct list of volume Names 60 | - "pvc-47f1af68-54fb-462c-b47b-443c267950b0" 61 | 62 | # Following are optional parameters 63 | # Log Level 64 | - "--v=4" 65 | # DO NOT CHANGE BELOW PARAMETERS 66 | env: 67 | - name: OPENEBS_NAMESPACE 68 | valueFrom: 69 | fieldRef: 70 | fieldPath: metadata.namespace 71 | tty: true 72 | 73 | # the image version should be same as the --to-version mentioned above 74 | # in the args of the job 75 | image: openebs/upgrade: 76 | imagePullPolicy: IfNotPresent 77 | restartPolicy: OnFailure 78 | --- 79 | 80 | -------------------------------------------------------------------------------- /examples/upgrade/jiva-volume.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 The OpenEBS Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This is an example YAML for upgrading cstor volume. 16 | # Some of the values below needs to be changed to 17 | # match your openebs installation. The fields are 18 | # indicated with VERIFY 19 | --- 20 | apiVersion: batch/v1 21 | kind: Job 22 | metadata: 23 | # VERIFY that you have provided a unique name for this upgrade job. 24 | # The name can be any valid K8s string for name. 25 | name: jiva-volume-upgrade 26 | 27 | # VERIFY the value of namespace is same as the namespace where openebs components 28 | # are installed. You can verify using the command: 29 | # `kubectl get pods -n -l openebs.io/component-name=maya-apiserver` 30 | # The above command should return status of the openebs-apiserver. 31 | namespace: openebs 32 | spec: 33 | template: 34 | spec: 35 | # VERIFY the value of serviceAccountName is pointing to service account 36 | # created within openebs namespace. Use the non-default account. 37 | # by running `kubectl get sa -n ` 38 | serviceAccountName: jiva-operator 39 | containers: 40 | - name: upgrade 41 | args: 42 | - "jiva-volume" 43 | 44 | # --from-version is the current version of the volume 45 | - "--from-version=2.6.0" 46 | 47 | # --to-version is the version desired upgrade version 48 | - "--to-version=2.7.0" 49 | # if required the image prefix of the volume deployments can be 50 | # changed using the flag below, defaults to whatever was present on old 51 | # deployments. 52 | #- "--to-version-image-prefix=openebs/" 53 | # if required the image tags for volume deployments can be changed 54 | # to a custom image tag using the flag below, 55 | # defaults to the --to-version mentioned above. 56 | #- "--to-version-image-tag=ci" 57 | 58 | # VERIFY that you have provided the correct list of volume Names 59 | - "pvc-1d4f7cf6-9da6-433a-a2f6-b22bdeb592f0" 60 | 61 | # Following are optional parameters 62 | # Log Level 63 | - "--v=4" 64 | # DO NOT CHANGE BELOW PARAMETERS 65 | env: 66 | - name: OPENEBS_NAMESPACE 67 | valueFrom: 68 | fieldRef: 69 | fieldPath: metadata.namespace 70 | tty: true 71 | 72 | # the image version should be same as the --to-version mentioned above 73 | # in the args of the job 74 | image: openebs/upgrade: 75 | imagePullPolicy: IfNotPresent 76 | restartPolicy: OnFailure 77 | --- 78 | 79 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/openebs/upgrade 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/google/go-cmp v0.6.0 7 | github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0 8 | github.com/openebs/api/v3 v3.0.4 9 | github.com/openebs/jiva-operator v1.12.2-0.20211126122511-b8b205d44bfa 10 | github.com/openebs/maya v1.12.1-0.20210308113344-5c43ada4c9e2 11 | github.com/pkg/errors v0.9.1 12 | github.com/spf13/cobra v1.7.0 13 | gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 14 | k8s.io/api v0.27.2 15 | k8s.io/apimachinery v0.27.2 16 | k8s.io/client-go v0.27.2 17 | k8s.io/klog/v2 v2.110.1 18 | k8s.io/kubectl v0.27.2 19 | sigs.k8s.io/controller-runtime v0.12.3 20 | ) 21 | 22 | require ( 23 | github.com/beorn7/perks v1.0.1 // indirect 24 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 25 | github.com/davecgh/go-spew v1.1.1 // indirect 26 | github.com/emicklei/go-restful/v3 v3.11.0 // indirect 27 | github.com/evanphx/json-patch v5.7.0+incompatible // indirect 28 | github.com/fsnotify/fsnotify v1.7.0 // indirect 29 | github.com/ghodss/yaml v1.0.0 // indirect 30 | github.com/go-errors/errors v1.0.1 // indirect 31 | github.com/go-logr/logr v1.3.0 // indirect 32 | github.com/go-logr/zapr v1.2.3 // indirect 33 | github.com/go-openapi/jsonpointer v0.20.0 // indirect 34 | github.com/go-openapi/jsonreference v0.20.2 // indirect 35 | github.com/go-openapi/swag v0.22.4 // indirect 36 | github.com/gogo/protobuf v1.3.2 // indirect 37 | github.com/golang/protobuf v1.5.3 // indirect 38 | github.com/google/gnostic v0.7.0 // indirect 39 | github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect 40 | github.com/google/gofuzz v1.2.0 // indirect 41 | github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect 42 | github.com/google/uuid v1.4.0 // indirect 43 | github.com/imdario/mergo v0.3.16 // indirect 44 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 45 | github.com/josharian/intern v1.0.0 // indirect 46 | github.com/json-iterator/go v1.1.12 // indirect 47 | github.com/mailru/easyjson v0.7.7 // indirect 48 | github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect 49 | github.com/moby/spdystream v0.2.0 // indirect 50 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 51 | github.com/modern-go/reflect2 v1.0.2 // indirect 52 | github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect 53 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 54 | github.com/prometheus/client_golang v1.17.0 // indirect 55 | github.com/prometheus/client_model v0.5.0 // indirect 56 | github.com/prometheus/common v0.45.0 // indirect 57 | github.com/prometheus/procfs v0.12.0 // indirect 58 | github.com/ryanuber/columnize v2.1.0+incompatible // indirect 59 | github.com/spf13/pflag v1.0.5 // indirect 60 | github.com/xlab/treeprint v1.1.0 // indirect 61 | go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect 62 | golang.org/x/net v0.19.0 // indirect 63 | golang.org/x/oauth2 v0.15.0 // indirect 64 | golang.org/x/sys v0.15.0 // indirect 65 | golang.org/x/term v0.15.0 // indirect 66 | golang.org/x/text v0.14.0 // indirect 67 | golang.org/x/time v0.5.0 // indirect 68 | gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect 69 | google.golang.org/appengine v1.6.8 // indirect 70 | google.golang.org/protobuf v1.31.0 // indirect 71 | gopkg.in/inf.v0 v0.9.1 // indirect 72 | gopkg.in/yaml.v2 v2.4.0 // indirect 73 | gopkg.in/yaml.v3 v3.0.1 // indirect 74 | k8s.io/apiextensions-apiserver v0.27.2 // indirect 75 | k8s.io/cli-runtime v0.25.16 // indirect 76 | k8s.io/klog v1.0.0 // indirect 77 | k8s.io/kube-openapi v0.0.0-20231206194836-bf4651e18aa8 // indirect 78 | k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect 79 | sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect 80 | sigs.k8s.io/kustomize/api v0.12.1 // indirect 81 | sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect 82 | sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect 83 | sigs.k8s.io/yaml v1.4.0 // indirect 84 | ) 85 | 86 | replace ( 87 | k8s.io/api => k8s.io/api v0.25.16 88 | k8s.io/apimachinery => k8s.io/apimachinery v0.25.16 89 | k8s.io/client-go => k8s.io/client-go v0.25.16 90 | k8s.io/kubectl => k8s.io/kubectl v0.25.16 91 | ) 92 | -------------------------------------------------------------------------------- /pkg/migrate/cstor/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package migrate 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | 23 | "k8s.io/apimachinery/pkg/util/strategicpatch" 24 | ) 25 | 26 | // GetPatchData returns patch data by 27 | // marshalling and taking diff of two objects 28 | func GetPatchData(oldObj, newObj interface{}) ([]byte, error) { 29 | oldData, err := json.Marshal(oldObj) 30 | if err != nil { 31 | return nil, fmt.Errorf("marshal old object failed: %v", err) 32 | } 33 | newData, err := json.Marshal(newObj) 34 | if err != nil { 35 | return nil, fmt.Errorf("mashal new object failed: %v", err) 36 | } 37 | patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, oldObj) 38 | if err != nil { 39 | return nil, fmt.Errorf("CreateTwoWayMergePatch failed: %v", err) 40 | } 41 | return patchBytes, nil 42 | } 43 | -------------------------------------------------------------------------------- /pkg/migrate/cstor/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package migrate 18 | 19 | var ( 20 | // IsMigrationTaskJob is used to determine 21 | // whether to report the utask errors. Errors 22 | // are reported only when job is triggered by 23 | // the resource command. 24 | IsMigrationTaskJob = false 25 | ) 26 | 27 | // Migrator abstracts the migration of a resource 28 | type Migrator interface { 29 | Migrate(name, namespace string) error 30 | } 31 | -------------------------------------------------------------------------------- /pkg/upgrade/exec.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package executor 18 | 19 | import ( 20 | upgrader "github.com/openebs/upgrade/pkg/upgrade/upgrader" 21 | ) 22 | 23 | // Exec ... 24 | func Exec(fromVersion, toVersion, kind, name, 25 | openebsNamespace, urlprefix, imagetag string) error { 26 | rp := upgrader.NewResourcePatch( 27 | upgrader.FromVersion(fromVersion), 28 | upgrader.ToVersion(toVersion), 29 | upgrader.WithName(name), 30 | upgrader.WithOpenebsNamespace(openebsNamespace), 31 | upgrader.WithBaseURL(urlprefix), 32 | upgrader.WithImageTag(imagetag), 33 | ) 34 | u := upgrader.NewUpgrade() 35 | err := u.UpgradeMap[kind](rp, u.Client).Upgrade() 36 | if err != nil { 37 | return err 38 | } 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/cspc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | apis "github.com/openebs/api/v3/pkg/apis/cstor/v1" 24 | clientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 25 | "github.com/pkg/errors" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/klog/v2" 29 | ) 30 | 31 | // CSPC ... 32 | type CSPC struct { 33 | Object *apis.CStorPoolCluster 34 | Data []byte 35 | Client clientset.Interface 36 | } 37 | 38 | // CSPCOptions ... 39 | type CSPCOptions func(*CSPC) 40 | 41 | // NewCSPC ... 42 | func NewCSPC(opts ...CSPCOptions) *CSPC { 43 | obj := &CSPC{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithCSPCClient ... 51 | func WithCSPCClient(c clientset.Interface) CSPCOptions { 52 | return func(obj *CSPC) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (c *CSPC) PreChecks(from, to string) error { 59 | if c.Object == nil { 60 | return errors.Errorf("nil cspc object") 61 | } 62 | version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] 63 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 64 | return errors.Errorf( 65 | "cspc version %s is neither %s nor %s", 66 | c.Object.VersionDetails.Status.Current, 67 | from, 68 | to, 69 | ) 70 | } 71 | return nil 72 | } 73 | 74 | // Patch ... 75 | func (c *CSPC) Patch(from, to string) error { 76 | klog.Info("patching cspc ", c.Object.Name) 77 | version := c.Object.VersionDetails.Desired 78 | if version == to { 79 | klog.Infof("cspc already in %s version", to) 80 | return nil 81 | } 82 | if version == from { 83 | patch := c.Data 84 | _, err := c.Client.CstorV1().CStorPoolClusters(c.Object.Namespace).Patch( 85 | context.TODO(), 86 | c.Object.Name, 87 | types.MergePatchType, 88 | []byte(patch), 89 | metav1.PatchOptions{}, 90 | ) 91 | if err != nil { 92 | return errors.Wrapf( 93 | err, 94 | "failed to patch cspc %s", 95 | c.Object.Name, 96 | ) 97 | } 98 | klog.Infof("cspc %s patched", c.Object.Name) 99 | } 100 | return nil 101 | } 102 | 103 | // Get ... 104 | func (c *CSPC) Get(name, namespace string) error { 105 | cspcObj, err := c.Client.CstorV1().CStorPoolClusters(namespace). 106 | Get(context.TODO(), name, metav1.GetOptions{}) 107 | if err != nil { 108 | return errors.Wrapf(err, "failed to get cspc %s in %s namespace", name, namespace) 109 | } 110 | c.Object = cspcObj 111 | return nil 112 | } 113 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/cspi.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | apis "github.com/openebs/api/v3/pkg/apis/cstor/v1" 24 | clientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 25 | "github.com/pkg/errors" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/klog/v2" 29 | ) 30 | 31 | // CSPI ... 32 | type CSPI struct { 33 | Object *apis.CStorPoolInstance 34 | Data []byte 35 | Client clientset.Interface 36 | } 37 | 38 | // CSPIOptions ... 39 | type CSPIOptions func(*CSPI) 40 | 41 | // NewCSPI ... 42 | func NewCSPI(opts ...CSPIOptions) *CSPI { 43 | obj := &CSPI{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithCSPIClient ... 51 | func WithCSPIClient(c clientset.Interface) CSPIOptions { 52 | return func(obj *CSPI) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (c *CSPI) PreChecks(from, to string) error { 59 | if c.Object == nil { 60 | return errors.Errorf("nil cspi object") 61 | } 62 | version := strings.Split(c.Object.Labels["openebs.io/version"], "-")[0] 63 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 64 | return errors.Errorf( 65 | "cspi version %s is neither %s nor %s", 66 | c.Object.Labels["openebs.io/version"], 67 | from, 68 | to, 69 | ) 70 | } 71 | return nil 72 | } 73 | 74 | // Patch ... 75 | func (c *CSPI) Patch(from, to string) error { 76 | klog.Info("patching cspi ", c.Object.Name) 77 | version := c.Object.Labels["openebs.io/version"] 78 | if version == to { 79 | klog.Infof("cspi already in %s version", to) 80 | return nil 81 | } 82 | if version == from { 83 | patch := c.Data 84 | _, err := c.Client.CstorV1().CStorPoolInstances(c.Object.Namespace).Patch( 85 | context.TODO(), 86 | c.Object.Name, 87 | types.MergePatchType, 88 | []byte(patch), 89 | metav1.PatchOptions{}, 90 | ) 91 | if err != nil { 92 | return errors.Wrapf( 93 | err, 94 | "failed to patch cspi %s", 95 | c.Object.Name, 96 | ) 97 | } 98 | klog.Infof("cspi %s patched", c.Object.Name) 99 | } 100 | return nil 101 | } 102 | 103 | // Get ... 104 | func (c *CSPI) Get(name, namespace string) error { 105 | cspi, err := c.Client.CstorV1().CStorPoolInstances(namespace). 106 | Get(context.TODO(), name, metav1.GetOptions{}) 107 | if err != nil { 108 | return errors.Wrapf(err, "failed to get cspi %s in %s namespace", name, namespace) 109 | } 110 | c.Object = cspi 111 | return nil 112 | } 113 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/cv.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | apis "github.com/openebs/api/v3/pkg/apis/cstor/v1" 24 | clientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 25 | "github.com/pkg/errors" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/klog/v2" 29 | ) 30 | 31 | // CV ... 32 | type CV struct { 33 | Object *apis.CStorVolume 34 | Data []byte 35 | Client clientset.Interface 36 | } 37 | 38 | // CVOptions ... 39 | type CVOptions func(*CV) 40 | 41 | // NewCV ... 42 | func NewCV(opts ...CVOptions) *CV { 43 | obj := &CV{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithCVClient ... 51 | func WithCVClient(c clientset.Interface) CVOptions { 52 | return func(obj *CV) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (c *CV) PreChecks(from, to string) error { 59 | if c.Object == nil { 60 | return errors.Errorf("nil cv object") 61 | } 62 | version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] 63 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 64 | return errors.Errorf( 65 | "cv version %s is neither %s nor %s", 66 | c.Object.VersionDetails.Status.Current, 67 | from, 68 | to, 69 | ) 70 | } 71 | return nil 72 | } 73 | 74 | // Patch ... 75 | func (c *CV) Patch(from, to string) error { 76 | klog.Info("patching cv ", c.Object.Name) 77 | version := c.Object.VersionDetails.Desired 78 | if version == to { 79 | klog.Infof("cv already in %s version", to) 80 | return nil 81 | } 82 | if version == from { 83 | patch := c.Data 84 | _, err := c.Client.CstorV1().CStorVolumes(c.Object.Namespace).Patch( 85 | context.TODO(), 86 | c.Object.Name, 87 | types.MergePatchType, 88 | []byte(patch), 89 | metav1.PatchOptions{}, 90 | ) 91 | if err != nil { 92 | return errors.Wrapf( 93 | err, 94 | "failed to patch cv %s", 95 | c.Object.Name, 96 | ) 97 | } 98 | klog.Infof("cv %s patched", c.Object.Name) 99 | } 100 | return nil 101 | } 102 | 103 | // Get ... 104 | func (c *CV) Get(name, namespace string) error { 105 | cvObj, err := c.Client.CstorV1().CStorVolumes(namespace). 106 | Get(context.TODO(), name, metav1.GetOptions{}) 107 | if err != nil { 108 | return errors.Wrapf(err, "failed to get cv %s in %s namespace", name, namespace) 109 | } 110 | c.Object = cvObj 111 | return nil 112 | } 113 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/cvc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | apis "github.com/openebs/api/v3/pkg/apis/cstor/v1" 24 | clientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 25 | "github.com/pkg/errors" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/klog/v2" 29 | ) 30 | 31 | // CVC ... 32 | type CVC struct { 33 | Object *apis.CStorVolumeConfig 34 | Data []byte 35 | Client clientset.Interface 36 | } 37 | 38 | // CVCOptions ... 39 | type CVCOptions func(*CVC) 40 | 41 | // NewCVC ... 42 | func NewCVC(opts ...CVCOptions) *CVC { 43 | obj := &CVC{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithCVCClient ... 51 | func WithCVCClient(c clientset.Interface) CVCOptions { 52 | return func(obj *CVC) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (c *CVC) PreChecks(from, to string) error { 59 | if c.Object == nil { 60 | return errors.Errorf("nil cvc object") 61 | } 62 | version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] 63 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 64 | return errors.Errorf( 65 | "cvc version %s is neither %s nor %s", 66 | c.Object.VersionDetails.Status.Current, 67 | from, 68 | to, 69 | ) 70 | } 71 | return nil 72 | } 73 | 74 | // Patch ... 75 | func (c *CVC) Patch(from, to string) error { 76 | klog.Info("patching cvc ", c.Object.Name) 77 | version := c.Object.VersionDetails.Desired 78 | if version == to { 79 | klog.Infof("cvc already in %s version", to) 80 | return nil 81 | } 82 | if version == from { 83 | patch := c.Data 84 | _, err := c.Client.CstorV1().CStorVolumeConfigs(c.Object.Namespace).Patch( 85 | context.TODO(), 86 | c.Object.Name, 87 | types.MergePatchType, 88 | []byte(patch), 89 | metav1.PatchOptions{}, 90 | ) 91 | if err != nil { 92 | return errors.Wrapf( 93 | err, 94 | "failed to patch cvc %s", 95 | c.Object.Name, 96 | ) 97 | } 98 | klog.Infof("cvc %s patched", c.Object.Name) 99 | } 100 | return nil 101 | } 102 | 103 | // Get ... 104 | func (c *CVC) Get(name, namespace string) error { 105 | cvcObj, err := c.Client.CstorV1().CStorVolumeConfigs(namespace). 106 | Get(context.TODO(), name, metav1.GetOptions{}) 107 | if err != nil { 108 | return errors.Wrapf(err, "failed to get cvc %s in %s namespace", name, namespace) 109 | } 110 | c.Object = cvcObj 111 | return nil 112 | } 113 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/cvr.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | apis "github.com/openebs/api/v3/pkg/apis/cstor/v1" 24 | clientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 25 | "github.com/pkg/errors" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/klog/v2" 29 | ) 30 | 31 | // CVR ... 32 | type CVR struct { 33 | Object *apis.CStorVolumeReplica 34 | Data []byte 35 | Client clientset.Interface 36 | } 37 | 38 | // CVROptions ... 39 | type CVROptions func(*CVR) 40 | 41 | // NewCVR ... 42 | func NewCVR(opts ...CVROptions) *CVR { 43 | obj := &CVR{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithCVRClient ... 51 | func WithCVRClient(c clientset.Interface) CVROptions { 52 | return func(obj *CVR) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (c *CVR) PreChecks(from, to string) error { 59 | if c.Object == nil { 60 | return errors.Errorf("nil cvr object") 61 | } 62 | version := strings.Split(c.Object.VersionDetails.Status.Current, "-")[0] 63 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 64 | return errors.Errorf( 65 | "cvr version %s is neither %s nor %s", 66 | c.Object.VersionDetails.Status.Current, 67 | from, 68 | to, 69 | ) 70 | } 71 | return nil 72 | } 73 | 74 | // Patch ... 75 | func (c *CVR) Patch(from, to string) error { 76 | klog.Info("patching cvr ", c.Object.Name) 77 | version := c.Object.VersionDetails.Desired 78 | if version == to { 79 | klog.Infof("cvr already in %s version", to) 80 | return nil 81 | } 82 | if version == from { 83 | patch := c.Data 84 | _, err := c.Client.CstorV1().CStorVolumeReplicas(c.Object.Namespace).Patch( 85 | context.TODO(), 86 | c.Object.Name, 87 | types.MergePatchType, 88 | []byte(patch), 89 | metav1.PatchOptions{}, 90 | ) 91 | if err != nil { 92 | return errors.Wrapf( 93 | err, 94 | "failed to patch cvr %s", 95 | c.Object.Name, 96 | ) 97 | } 98 | klog.Infof("cvr %s patched", c.Object.Name) 99 | } 100 | return nil 101 | } 102 | 103 | // Get ... 104 | func (c *CVR) Get(name, namespace string) error { 105 | cvrObj, err := c.Client.CstorV1().CStorVolumeReplicas(namespace). 106 | Get(context.TODO(), name, metav1.GetOptions{}) 107 | if err != nil { 108 | return errors.Wrapf(err, "failed to get cvr %s in %s namespace", name, namespace) 109 | } 110 | c.Object = cvrObj 111 | return nil 112 | } 113 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/deployment.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | "time" 23 | 24 | "github.com/pkg/errors" 25 | appsv1 "k8s.io/api/apps/v1" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/client-go/kubernetes" 29 | "k8s.io/klog/v2" 30 | deploymentutil "k8s.io/kubectl/pkg/util/deployment" 31 | ) 32 | 33 | // Deployment ... 34 | type Deployment struct { 35 | Object *appsv1.Deployment 36 | Data []byte 37 | Client kubernetes.Interface 38 | } 39 | 40 | // DeploymentOptions ... 41 | type DeploymentOptions func(*Deployment) 42 | 43 | // NewDeployment ... 44 | func NewDeployment(opts ...DeploymentOptions) *Deployment { 45 | obj := &Deployment{} 46 | for _, o := range opts { 47 | o(obj) 48 | } 49 | return obj 50 | } 51 | 52 | // WithDeploymentClient ... 53 | func WithDeploymentClient(c kubernetes.Interface) DeploymentOptions { 54 | return func(obj *Deployment) { 55 | obj.Client = c 56 | } 57 | } 58 | 59 | // PreChecks ... 60 | func (d *Deployment) PreChecks(from, to string) error { 61 | if d.Object == nil { 62 | return errors.Errorf("nil deployment object") 63 | } 64 | version := strings.Split(d.Object.Labels["openebs.io/version"], "-")[0] 65 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 66 | return errors.Errorf( 67 | "deployment version %s is neither %s nor %s", 68 | d.Object.Labels["openebs.io/version"], 69 | from, 70 | to, 71 | ) 72 | } 73 | return nil 74 | } 75 | 76 | // Patch ... 77 | func (d *Deployment) Patch(from, to string) error { 78 | klog.Info("patching deployment ", d.Object.Name) 79 | version := d.Object.Labels["openebs.io/version"] 80 | if version == to { 81 | klog.Infof("deployment already in %s version", to) 82 | return nil 83 | } 84 | if version == from { 85 | _, err := d.Client.AppsV1().Deployments(d.Object.Namespace).Patch( 86 | context.TODO(), 87 | d.Object.Name, 88 | types.StrategicMergePatchType, 89 | d.Data, 90 | metav1.PatchOptions{}, 91 | ) 92 | if err != nil { 93 | return errors.Wrapf( 94 | err, 95 | "failed to patch deployment %s", 96 | d.Object.Name, 97 | ) 98 | } 99 | time.Sleep(2 * time.Second) 100 | for { 101 | deployObj, err1 := d.Client.AppsV1().Deployments(d.Object.Namespace). 102 | Get(context.TODO(), d.Object.Name, metav1.GetOptions{}) 103 | if err1 != nil { 104 | return err1 105 | } 106 | revision, err1 := deploymentutil.Revision(deployObj) 107 | if err1 != nil { 108 | return err1 109 | } 110 | statusViewer := DeploymentStatusViewer{} 111 | msg, rolledOut, err1 := statusViewer.Status(deployObj, revision) 112 | if err1 != nil { 113 | return err1 114 | } 115 | klog.Info("rollout status: ", msg) 116 | if !rolledOut { 117 | time.Sleep(5 * time.Second) 118 | } else { 119 | break 120 | } 121 | } 122 | klog.Infof("deployment %s patched successfully", d.Object.Name) 123 | } 124 | return nil 125 | } 126 | 127 | // Get ... 128 | func (d *Deployment) Get(label, namespace string) error { 129 | deployments, err := d.Client.AppsV1().Deployments(namespace).List(context.TODO(), 130 | metav1.ListOptions{ 131 | LabelSelector: label, 132 | }, 133 | ) 134 | if err != nil { 135 | return errors.Wrapf(err, "failed to get deployment for %s", label) 136 | } 137 | if len(deployments.Items) != 1 { 138 | return errors.Errorf("no deployments found for label: %s in %s namespace", label, namespace) 139 | } 140 | d.Object = &deployments.Items[0] 141 | return nil 142 | } 143 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | // Patcher abstracts the patching of components 20 | type Patcher interface { 21 | PreChecks(from, to string) error 22 | Patch(from, to string) error 23 | // TODO 24 | // Validate() error 25 | } 26 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/jivavolume.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | // clientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 24 | jv "github.com/openebs/jiva-operator/pkg/apis/openebs/v1" 25 | "github.com/pkg/errors" 26 | "k8s.io/apimachinery/pkg/types" 27 | "k8s.io/klog/v2" 28 | "sigs.k8s.io/controller-runtime/pkg/client" 29 | ) 30 | 31 | // JV ... 32 | type JV struct { 33 | Object *jv.JivaVolume 34 | NewObject *jv.JivaVolume 35 | Client client.Client 36 | } 37 | 38 | // JVOptions ... 39 | type JVOptions func(*JV) 40 | 41 | // NewJV ... 42 | func NewJV(opts ...JVOptions) *JV { 43 | obj := &JV{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithJVClient ... 51 | func WithJVClient(c client.Client) JVOptions { 52 | return func(obj *JV) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (j *JV) PreChecks(from, to string) error { 59 | if j.Object == nil { 60 | return errors.Errorf("nil jivaVolume object") 61 | } 62 | version := strings.Split(j.Object.VersionDetails.Status.Current, "-")[0] 63 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 64 | return errors.Errorf( 65 | "jivaVolume version %s is neither %s nor %s", 66 | j.Object.VersionDetails.Status.Current, 67 | from, 68 | to, 69 | ) 70 | } 71 | return nil 72 | } 73 | 74 | // Patch ... 75 | func (j *JV) Patch(from, to string) error { 76 | klog.Info("patching jivaVolume ", j.Object.Name) 77 | version := j.Object.VersionDetails.Desired 78 | if version == to { 79 | klog.Infof("jivaVolume already in %s version", to) 80 | return nil 81 | } 82 | if version == from { 83 | patch := client.MergeFrom(j.Object) 84 | err := j.Client.Patch( 85 | context.TODO(), 86 | j.NewObject, 87 | patch, 88 | ) 89 | if err != nil { 90 | return errors.Wrapf( 91 | err, 92 | "failed to patch jivaVolume %s", 93 | j.Object.Name, 94 | ) 95 | } 96 | klog.Infof("jivaVolume %s patched", j.Object.Name) 97 | } 98 | return nil 99 | } 100 | 101 | func (j *JV) Get(name, namespace string) error { 102 | instance := &jv.JivaVolume{} 103 | if err := j.Client.Get(context.TODO(), 104 | types.NamespacedName{ 105 | Name: name, 106 | Namespace: namespace, 107 | }, instance); err != nil { 108 | return errors.Wrapf(err, "failed to get jivaVolume %s in %s namespace", name, namespace) 109 | } 110 | 111 | // update cr with the latest change 112 | j.Object = instance.DeepCopy() 113 | return nil 114 | } 115 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/service.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | 23 | "github.com/pkg/errors" 24 | corev1 "k8s.io/api/core/v1" 25 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | "k8s.io/apimachinery/pkg/types" 27 | "k8s.io/client-go/kubernetes" 28 | "k8s.io/klog/v2" 29 | ) 30 | 31 | // Service ... 32 | type Service struct { 33 | Object *corev1.Service 34 | Data []byte 35 | Client kubernetes.Interface 36 | } 37 | 38 | // ServiceOptions ... 39 | type ServiceOptions func(*Service) 40 | 41 | // NewService ... 42 | func NewService(opts ...ServiceOptions) *Service { 43 | obj := &Service{} 44 | for _, o := range opts { 45 | o(obj) 46 | } 47 | return obj 48 | } 49 | 50 | // WithKubeClient ... 51 | func WithKubeClient(c kubernetes.Interface) ServiceOptions { 52 | return func(obj *Service) { 53 | obj.Client = c 54 | } 55 | } 56 | 57 | // PreChecks ... 58 | func (s *Service) PreChecks(from, to string) error { 59 | name := s.Object.Name 60 | if name == "" { 61 | return errors.Errorf("missing service name") 62 | } 63 | version := strings.Split(s.Object.Labels["openebs.io/version"], "-")[0] 64 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 65 | return errors.Errorf( 66 | "service version %s is neither %s nor %s", 67 | s.Object.Labels["openebs.io/version"], 68 | from, 69 | to, 70 | ) 71 | } 72 | return nil 73 | } 74 | 75 | // Patch ... 76 | func (s *Service) Patch(from, to string) error { 77 | klog.Info("Patching service ", s.Object.Name) 78 | version := s.Object.Labels["openebs.io/version"] 79 | if version == to { 80 | klog.Infof("service already in %s version", to) 81 | return nil 82 | } 83 | if version == from { 84 | patch := s.Data 85 | _, err := s.Client.CoreV1().Services(s.Object.Namespace).Patch( 86 | context.TODO(), 87 | s.Object.Name, 88 | types.StrategicMergePatchType, 89 | []byte(patch), 90 | metav1.PatchOptions{}, 91 | ) 92 | if err != nil { 93 | return errors.Wrapf( 94 | err, 95 | "failed to patch service %s", 96 | s.Object.Name, 97 | ) 98 | } 99 | klog.Infof("Service %s patched", s.Object.Name) 100 | } 101 | return nil 102 | } 103 | 104 | // Get ... 105 | func (s *Service) Get(label, namespace string) error { 106 | service, err := s.Client.CoreV1().Services(namespace).List( 107 | context.TODO(), 108 | metav1.ListOptions{ 109 | LabelSelector: label, 110 | }, 111 | ) 112 | if err != nil { 113 | return errors.Wrapf(err, "failed to get service for %s", label) 114 | } 115 | s.Object = &service.Items[0] 116 | return nil 117 | } 118 | -------------------------------------------------------------------------------- /pkg/upgrade/patch/statefulset.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implies. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package patch 18 | 19 | import ( 20 | "context" 21 | "strings" 22 | "time" 23 | 24 | "github.com/pkg/errors" 25 | appsv1 "k8s.io/api/apps/v1" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/types" 28 | "k8s.io/client-go/kubernetes" 29 | "k8s.io/klog/v2" 30 | ) 31 | 32 | // StatefulSet ... 33 | type StatefulSet struct { 34 | Object *appsv1.StatefulSet 35 | Data []byte 36 | Client kubernetes.Interface 37 | } 38 | 39 | // StatefulSetOptions ... 40 | type StatefulSetOptions func(*StatefulSet) 41 | 42 | // NewStatefulSet ... 43 | func NewStatefulSet(opts ...StatefulSetOptions) *StatefulSet { 44 | obj := &StatefulSet{} 45 | for _, o := range opts { 46 | o(obj) 47 | } 48 | return obj 49 | } 50 | 51 | // WithStatefulSetClient ... 52 | func WithStatefulSetClient(c kubernetes.Interface) StatefulSetOptions { 53 | return func(obj *StatefulSet) { 54 | obj.Client = c 55 | } 56 | } 57 | 58 | // PreChecks ... 59 | func (s *StatefulSet) PreChecks(from, to string) error { 60 | if s.Object == nil { 61 | return errors.Errorf("nil statefulset object") 62 | } 63 | version := strings.Split(s.Object.Labels["openebs.io/version"], "-")[0] 64 | if version != strings.Split(from, "-")[0] && version != strings.Split(to, "-")[0] { 65 | return errors.Errorf( 66 | "statefulset version %s is neither %s nor %s", 67 | s.Object.Labels["openebs.io/version"], 68 | from, 69 | to, 70 | ) 71 | } 72 | return nil 73 | } 74 | 75 | // Patch ... 76 | func (s *StatefulSet) Patch(from, to string) error { 77 | klog.Info("patching statefulset ", s.Object.Name) 78 | version := s.Object.Labels["openebs.io/version"] 79 | if version == to { 80 | klog.Infof("statefulset already in %s version", to) 81 | return nil 82 | } 83 | if version == from { 84 | _, err := s.Client.AppsV1().StatefulSets(s.Object.Namespace).Patch( 85 | context.TODO(), 86 | s.Object.Name, 87 | types.StrategicMergePatchType, 88 | s.Data, 89 | metav1.PatchOptions{}, 90 | ) 91 | if err != nil { 92 | return errors.Wrapf( 93 | err, 94 | "failed to patch statefulset %s", 95 | s.Object.Name, 96 | ) 97 | } 98 | for { 99 | stsObj, err1 := s.Client.AppsV1().StatefulSets(s.Object.Namespace). 100 | Get(context.TODO(), s.Object.Name, metav1.GetOptions{}) 101 | if err != nil { 102 | return err1 103 | } 104 | statusViewer := StatefulSetStatusViewer{} 105 | msg, rolledOut, err1 := statusViewer.Status(stsObj) 106 | if err1 != nil { 107 | return err1 108 | } 109 | klog.Info("rollout status: ", msg) 110 | if !rolledOut { 111 | time.Sleep(5 * time.Second) 112 | } else { 113 | break 114 | } 115 | } 116 | klog.Infof("statefulset %s patched successfully", s.Object.Name) 117 | } 118 | return nil 119 | } 120 | 121 | // Get ... 122 | func (s *StatefulSet) Get(label, namespace string) error { 123 | statefulsets, err := s.Client.AppsV1().StatefulSets(namespace).List( 124 | context.TODO(), 125 | metav1.ListOptions{ 126 | LabelSelector: label, 127 | }, 128 | ) 129 | if err != nil { 130 | return errors.Wrapf(err, "failed to get statefulset for %s", label) 131 | } 132 | if len(statefulsets.Items) != 1 { 133 | return errors.Errorf("no statefulsets found for label: %s in %s namespace", label, namespace) 134 | } 135 | s.Object = &statefulsets.Items[0] 136 | return nil 137 | } 138 | -------------------------------------------------------------------------------- /pkg/upgrade/upgrader/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package upgrader 18 | 19 | import ( 20 | "context" 21 | "encoding/json" 22 | "fmt" 23 | "strings" 24 | 25 | "github.com/pkg/errors" 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | "k8s.io/apimachinery/pkg/util/strategicpatch" 28 | "k8s.io/client-go/kubernetes" 29 | ) 30 | 31 | var ( 32 | cstorOperatorServiceAccount = "openebs-cstor-operator" 33 | ) 34 | 35 | func getImageURL(url, prefix string) (string, error) { 36 | lastIndex := strings.LastIndex(url, ":") 37 | if lastIndex == -1 { 38 | return "", errors.Errorf("no version tag found on image %s", url) 39 | } 40 | baseImage := url[:lastIndex] 41 | if prefix != "" { 42 | // urlPrefix is the url to the directory where the images are present 43 | // the below logic takes the image name from current baseImage and 44 | // appends it to the given urlPrefix 45 | // For example baseImage is abc/quay.io/openebs/jiva 46 | // and urlPrefix is xyz/aws-56546546/openebsdirectory/ 47 | // it will take jiva from current url and append it to urlPrefix 48 | // and return xyz/aws-56546546/openebsdirectory/jiva 49 | urlSubstr := strings.Split(baseImage, "/") 50 | baseImage = prefix + urlSubstr[len(urlSubstr)-1] 51 | } 52 | return baseImage, nil 53 | } 54 | 55 | // GetPatchData returns patch data by 56 | // marshalling and taking diff of two objects 57 | func GetPatchData(oldObj, newObj interface{}) ([]byte, error) { 58 | oldData, err := json.Marshal(oldObj) 59 | if err != nil { 60 | return nil, fmt.Errorf("marshal old object failed: %v", err) 61 | } 62 | newData, err := json.Marshal(newObj) 63 | if err != nil { 64 | return nil, fmt.Errorf("mashal new object failed: %v", err) 65 | } 66 | patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, oldObj) 67 | if err != nil { 68 | return nil, fmt.Errorf("CreateTwoWayMergePatch failed: %v", err) 69 | } 70 | return patchBytes, nil 71 | } 72 | 73 | func isOperatorUpgraded(componentName string, namespace string, 74 | toVersion string, kubeClient kubernetes.Interface) error { 75 | operatorPods, err := kubeClient.CoreV1(). 76 | Pods(namespace). 77 | List(context.TODO(), metav1.ListOptions{ 78 | LabelSelector: "openebs.io/component-name=" + componentName, 79 | }) 80 | if err != nil { 81 | return err 82 | } 83 | if len(operatorPods.Items) == 0 { 84 | return fmt.Errorf("operator pod missing for %s", componentName) 85 | } 86 | for _, pod := range operatorPods.Items { 87 | if pod.Labels["openebs.io/version"] != toVersion { 88 | return fmt.Errorf("%s is in %s version, please upgrade it to %s version", 89 | componentName, pod.Labels["openebs.io/version"], toVersion) 90 | } 91 | } 92 | if componentName == "cspc-operator" || componentName == "cvc-operator" { 93 | cstorOperatorServiceAccount = operatorPods.Items[0].Spec.ServiceAccountName 94 | } 95 | return nil 96 | } 97 | 98 | // Remove the suffix only if it is present 99 | // at the end of the string 100 | func removeSuffixFromEnd(str, suffix string) string { 101 | slice := strings.Split(str, "/") 102 | // if the image is from openebs registry and has a suffix -amd64 103 | // then only perform the operation 104 | if slice[len(slice)-2] == "openebs" && strings.HasSuffix(slice[len(slice)-1], "-amd64") { 105 | i := strings.LastIndex(str, suffix) 106 | if i > -1 && i == len(str)-len(suffix) { 107 | str = str[:i] 108 | } 109 | } 110 | return str 111 | } 112 | -------------------------------------------------------------------------------- /pkg/upgrade/upgrader/helper_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package upgrader 18 | 19 | import "testing" 20 | 21 | func Test_removeSuffixFromEnd(t *testing.T) { 22 | type args struct { 23 | str string 24 | suffix string 25 | } 26 | tests := []struct { 27 | name string 28 | args args 29 | want string 30 | }{ 31 | { 32 | name: "with suffix", 33 | args: args{ 34 | str: "openebs/cstor-operator-amd64", 35 | suffix: "-amd64", 36 | }, 37 | want: "openebs/cstor-operator", 38 | }, 39 | { 40 | name: "without suffix", 41 | args: args{ 42 | str: "openebs/cstor-operator", 43 | suffix: "-amd64", 44 | }, 45 | want: "openebs/cstor-operator", 46 | }, 47 | { 48 | name: "airgap with suffix", 49 | args: args{ 50 | str: "air-gap-having-amd64/openebs/cstor-operator-amd64", 51 | suffix: "-amd64", 52 | }, 53 | want: "air-gap-having-amd64/openebs/cstor-operator", 54 | }, 55 | { 56 | name: "airgap without suffix", 57 | args: args{ 58 | str: "air-gap-having-amd64/openebs/cstor-operator", 59 | suffix: "-amd64", 60 | }, 61 | want: "air-gap-having-amd64/openebs/cstor-operator", 62 | }, 63 | { 64 | name: "custom repository with suffix", 65 | args: args{ 66 | str: "air-gap-having-amd64/custom/cstor-operator-amd64", 67 | suffix: "-amd64", 68 | }, 69 | want: "air-gap-having-amd64/custom/cstor-operator-amd64", 70 | }, 71 | { 72 | name: "custom repository without suffix", 73 | args: args{ 74 | str: "air-gap-having-amd64/custom/cstor-operator", 75 | suffix: "-amd64", 76 | }, 77 | want: "air-gap-having-amd64/custom/cstor-operator", 78 | }, 79 | } 80 | for _, tt := range tests { 81 | t.Run(tt.name, func(t *testing.T) { 82 | if got := removeSuffixFromEnd(tt.args.str, tt.args.suffix); got != tt.want { 83 | t.Errorf("removeSuffix() = %v, want %v", got, tt.want) 84 | } 85 | }) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /pkg/upgrade/upgrader/interface.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package upgrader 18 | 19 | // Upgrader abstracts the upgrade of a resource 20 | type Upgrader interface { 21 | Upgrade() error 22 | } 23 | -------------------------------------------------------------------------------- /pkg/upgrade/upgrader/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package upgrader 18 | 19 | func (u *Upgrade) registerUpgrade(kind string, obj UpgradeOptions) *Upgrade { 20 | u.UpgradeMap[kind] = obj 21 | return u 22 | } 23 | 24 | // RegisterAll ... 25 | func (u *Upgrade) RegisterAll() *Upgrade { 26 | u.registerUpgrade("cstorPoolInstance", RegisterCstorPoolInstance) 27 | u.registerUpgrade("cstorPoolCluster", RegisterCstorPoolCluster) 28 | u.registerUpgrade("cstorVolume", RegisterCstorVolume) 29 | u.registerUpgrade("jivaVolume", RegisterJivaVolume) 30 | return u 31 | } 32 | 33 | // RegisterCstorPoolInstance .... 34 | func RegisterCstorPoolInstance(r *ResourcePatch, c *Client) Upgrader { 35 | obj := NewCSPIPatch( 36 | WithCSPIResorcePatch(r), 37 | WithCSPIClient(c), 38 | ) 39 | return obj 40 | } 41 | 42 | // RegisterCstorPoolCluster ... 43 | func RegisterCstorPoolCluster(r *ResourcePatch, c *Client) Upgrader { 44 | obj := NewCSPCPatch( 45 | WithCSPCResorcePatch(r), 46 | WithCSPCClient(c), 47 | ) 48 | return obj 49 | } 50 | 51 | // RegisterCstorVolume .... 52 | func RegisterCstorVolume(r *ResourcePatch, c *Client) Upgrader { 53 | obj := NewCStorVolumePatch( 54 | WithCStorVolumeResorcePatch(r), 55 | WithCStorVolumeClient(c), 56 | ) 57 | return obj 58 | } 59 | 60 | // RegisterCstorVolume .... 61 | func RegisterJivaVolume(r *ResourcePatch, c *Client) Upgrader { 62 | obj := NewJivaVolumePatch( 63 | WithJivaVolumeResorcePatch(r), 64 | WithJivaVolumeClient(c), 65 | ) 66 | return obj 67 | } 68 | -------------------------------------------------------------------------------- /pkg/upgrade/upgrader/resourcepatch.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package upgrader 18 | 19 | // ResourcePatch has all the patches required to upgrade a resource 20 | type ResourcePatch struct { 21 | Name string 22 | OpenebsNamespace string 23 | From, To string 24 | ImageTag, BaseURL string 25 | // UpgradeTask *utask.UpgradeTask 26 | } 27 | 28 | // ResourcePatchOptions ... 29 | type ResourcePatchOptions func(*ResourcePatch) 30 | 31 | // WithName ... 32 | func WithName(name string) ResourcePatchOptions { 33 | return func(r *ResourcePatch) { 34 | r.Name = name 35 | } 36 | } 37 | 38 | // FromVersion ... 39 | func FromVersion(from string) ResourcePatchOptions { 40 | return func(r *ResourcePatch) { 41 | r.From = from 42 | } 43 | } 44 | 45 | // ToVersion ... 46 | func ToVersion(to string) ResourcePatchOptions { 47 | return func(r *ResourcePatch) { 48 | r.To = to 49 | } 50 | } 51 | 52 | // WithOpenebsNamespace ... 53 | func WithOpenebsNamespace(namespace string) ResourcePatchOptions { 54 | return func(r *ResourcePatch) { 55 | r.OpenebsNamespace = namespace 56 | } 57 | } 58 | 59 | // WithImageTag ... 60 | func WithImageTag(imagetag string) ResourcePatchOptions { 61 | return func(r *ResourcePatch) { 62 | r.ImageTag = imagetag 63 | } 64 | } 65 | 66 | // WithBaseURL ... 67 | func WithBaseURL(url string) ResourcePatchOptions { 68 | return func(r *ResourcePatch) { 69 | r.BaseURL = url 70 | } 71 | } 72 | 73 | // NewResourcePatch returns a new instance of ResourcePatch 74 | func NewResourcePatch(opts ...ResourcePatchOptions) *ResourcePatch { 75 | r := &ResourcePatch{} 76 | for _, o := range opts { 77 | o(r) 78 | } 79 | return r 80 | } 81 | -------------------------------------------------------------------------------- /pkg/upgrade/upgrader/upgrade.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package upgrader 18 | 19 | import ( 20 | "os" 21 | 22 | openebsclientset "github.com/openebs/api/v3/pkg/client/clientset/versioned" 23 | "github.com/pkg/errors" 24 | "k8s.io/client-go/kubernetes" 25 | "k8s.io/client-go/rest" 26 | ) 27 | 28 | var ( 29 | isUpgradeTaskJob = false 30 | ) 31 | 32 | // UpgradeOptions ... 33 | type UpgradeOptions func(*ResourcePatch, *Client) Upgrader 34 | 35 | // Client ... 36 | type Client struct { 37 | // kubeclientset is a standard kubernetes clientset 38 | KubeClientset kubernetes.Interface 39 | // openebsclientset is a openebs custom resource package generated for custom API group. 40 | OpenebsClientset openebsclientset.Interface 41 | } 42 | 43 | // Upgrade ... 44 | type Upgrade struct { 45 | UpgradeMap map[string]UpgradeOptions 46 | *Client 47 | } 48 | 49 | func (u *Upgrade) initClient() error { 50 | cfg, err := rest.InClusterConfig() 51 | if err != nil { 52 | return errors.Wrap(err, "error building kubeconfig") 53 | } 54 | u.KubeClientset, err = kubernetes.NewForConfig(cfg) 55 | if err != nil { 56 | return errors.Wrap(err, "error building kubernetes clientset") 57 | } 58 | u.OpenebsClientset, err = openebsclientset.NewForConfig(cfg) 59 | if err != nil { 60 | return errors.Wrap(err, "error building openebs clientset") 61 | } 62 | return nil 63 | } 64 | 65 | // NewUpgrade ... 66 | func NewUpgrade() *Upgrade { 67 | u := &Upgrade{ 68 | UpgradeMap: map[string]UpgradeOptions{}, 69 | Client: &Client{}, 70 | } 71 | u.initClient() 72 | u.RegisterAll() 73 | if os.Getenv("UPGRADE_TASK_LABEL") != "" { 74 | isUpgradeTaskJob = true 75 | } 76 | return u 77 | } 78 | -------------------------------------------------------------------------------- /pkg/version/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package version 18 | 19 | import ( 20 | "strings" 21 | ) 22 | 23 | var ( 24 | validCurrentVersions = map[string]bool{ 25 | "1.10.0": true, "1.11.0": true, "1.12.0": true, 26 | "2.0.0": true, "2.1.0": true, "2.2.0": true, "2.3.0": true, 27 | "2.4.0": true, "2.4.1": true, "2.5.0": true, "2.6.0": true, 28 | "2.7.0": true, "2.8.0": true, "2.9.0": true, "2.10.0": true, 29 | "2.10.1": true, "2.11.0": true, "2.12.0": true, "2.12.1": true, 30 | "2.12.2": true, "3.0.0": true, "3.1.0": true, "3.2.0": true, 31 | "3.3.0": true, "3.4.0": true, "3.5.0": true, 32 | } 33 | validDesiredVersion = strings.Split(GetVersion(), "-")[0] 34 | ) 35 | 36 | // IsCurrentVersionValid verifies if the current version is valid or not 37 | func IsCurrentVersionValid(v string) bool { 38 | currentVersion := strings.Split(v, "-")[0] 39 | return validCurrentVersions[currentVersion] 40 | } 41 | 42 | // IsDesiredVersionValid verifies the desired version is valid or not 43 | func IsDesiredVersionValid(v string) bool { 44 | desiredVersion := strings.Split(v, "-")[0] 45 | return validDesiredVersion == desiredVersion 46 | } 47 | -------------------------------------------------------------------------------- /pkg/version/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The OpenEBS Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package version 18 | 19 | import ( 20 | "io/ioutil" 21 | "os" 22 | "os/exec" 23 | "path/filepath" 24 | "strings" 25 | ) 26 | 27 | var ( 28 | // GitCommit that was compiled. This will be filled in by the compiler. 29 | GitCommit string 30 | 31 | // Version show the version number,fill in by the compiler 32 | Version string 33 | 34 | // VersionMeta is a pre-release marker for the version. If this is "" (empty string) 35 | // then it means that it is a final release. Otherwise, this is a pre-release 36 | // such as "dev" (in development), "beta", "rc1", etc. 37 | VersionMeta string 38 | ) 39 | 40 | const ( 41 | versionFile string = "/src/github.com/openebs/upgrade/VERSION" 42 | 43 | // versionDelimiter is used as a delimiter to separate version info 44 | versionDelimiter string = "-" 45 | 46 | // versionChars consist of valid version characters 47 | versionChars string = ".0123456789" 48 | ) 49 | 50 | // IsNotVersioned returns true if the given string does not have version as its 51 | // suffix 52 | func IsNotVersioned(given string) bool { 53 | return !IsVersioned(given) 54 | } 55 | 56 | // IsVersioned returns true if the given string has version as its suffix 57 | func IsVersioned(given string) bool { 58 | a := strings.SplitAfter(given, versionDelimiter) 59 | if len(a) == 0 { 60 | return false 61 | } 62 | ver := a[len(a)-1] 63 | return len(strings.Split(ver, ".")) == 3 && containsOnly(ver, versionChars) 64 | } 65 | 66 | // containsOnly returns true if provided string consists only of the provided 67 | // set 68 | func containsOnly(s string, set string) bool { 69 | return strings.IndexFunc(s, func(r rune) bool { 70 | return !strings.ContainsRune(set, r) 71 | }) == -1 72 | } 73 | 74 | // WithSuffix appends current version to the provided string 75 | func WithSuffix(given string) (suffixed string) { 76 | return given + versionDelimiter + Current() 77 | } 78 | 79 | // WithSuffixIf appends current version to the provided string if given predicate 80 | // succeeds 81 | func WithSuffixIf(given string, p func(string) bool) (suffixed string) { 82 | if p(given) { 83 | return WithSuffix(given) 84 | } 85 | return given 86 | } 87 | 88 | // WithSuffixesIf appends current version to the provided strings 89 | func WithSuffixesIf(given []string, p func(string) bool) (suffixed []string) { 90 | for _, s := range given { 91 | if p(s) { 92 | suffixed = append(suffixed, WithSuffix(s)) 93 | } else { 94 | suffixed = append(suffixed, s) 95 | } 96 | } 97 | return 98 | } 99 | 100 | // Current returns the current version of maya 101 | func Current() string { 102 | return GetVersion() 103 | } 104 | 105 | // GetVersion returns the current version from the global Version variable. 106 | // If Version is unset then from the VERSION file at the root of the repo. 107 | func GetVersion() string { 108 | if Version != "" { 109 | return Version 110 | } 111 | path := filepath.Join(os.Getenv("GOPATH") + versionFile) 112 | vBytes, err := ioutil.ReadFile(path) 113 | if err != nil { 114 | // ignore error 115 | return "" 116 | } 117 | return strings.TrimSpace(string(vBytes)) 118 | } 119 | 120 | // GetGitCommit returns the Git commit SHA-1 from the global GitCommit variable. 121 | // If GitCommit is unset then by calling Git directly. 122 | func GetGitCommit() string { 123 | if GitCommit != "" { 124 | return GitCommit 125 | } 126 | cmd := exec.Command("git", "rev-parse", "--verify", "HEAD") 127 | output, err := cmd.Output() 128 | if err != nil { 129 | // ignore error 130 | return "" 131 | } 132 | return strings.TrimSpace(string(output)) 133 | } 134 | 135 | func GetVersionDetails() string { 136 | return strings.Join([]string{GetVersion(), GetGitCommit()[0:7]}, "-") 137 | } 138 | --------------------------------------------------------------------------------