diff --git a/.github/actions/deploy-lifecycle-manager-e2e/action.yml b/.github/actions/deploy-lifecycle-manager-e2e/action.yml index 38714fe8a6..1d1526a83d 100644 --- a/.github/actions/deploy-lifecycle-manager-e2e/action.yml +++ b/.github/actions/deploy-lifecycle-manager-e2e/action.yml @@ -97,6 +97,51 @@ runs: cat certificate_renewal.yaml kustomize edit add patch --path certificate_renewal.yaml --kind Certificate --group cert-manager.io --version v1 --name watcher-serving popd + - name: Create and use maintenance window policy + if: ${{matrix.e2e-test == 'maintenance-window-with-module-downtime'}} + working-directory: lifecycle-manager/config + shell: bash + run: | + current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + time_plus_2_hours=$(date -u -d "2 hours" +"%Y-%m-%dT%H:%M:%SZ") + time_plus_1_day=$(date -u -d "1 day" +"%Y-%m-%dT%H:%M:%SZ") + time_plus_1_day_plus_2_hours=$(date -u -d "1 day 2 hours" +"%Y-%m-%dT%H:%M:%SZ") + + cat < ./maintenance_windows/policy.json + { + "rules": [ + { + "match": { + "region": "asia" + }, + "windows": [ + { + "begin": "$current_time", + "end": "$time_plus_2_hours" + } + ] + }, + { + "match": { + "region": "europe" + }, + "windows": [ + { + "begin": "$time_plus_1_day", + "end": "$time_plus_1_day_plus_2_hours" + } + ] + } + ], + "default": {} + } + EOF + + echo "Maintenance window policy:" + cat ./maintenance_windows/policy.json + + cd watcher_local_test + kustomize edit add component ../maintenance_windows - name: Deploy LM local testing kustomize uses: ./lifecycle-manager/.github/actions/deploy-lifecycle-manager with: diff --git a/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml b/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml index b91fc5e082..6afca737d2 100644 --- a/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml +++ b/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml @@ -42,13 +42,22 @@ runs: - name: Create and apply Template Operator ModuleTemplate with ModuleDeploymentNameInNewerVersion working-directory: template-operator if: ${{ matrix.e2e-test != 'mandatory-module' && - matrix.e2e-test != 'mandatory-module-metrics' + matrix.e2e-test != 'mandatory-module-metrics' }} shell: bash run: | + INCLUDE_DEFAULT_CR=true + MANDATORY=false + DEPLOY_MODULETEMPLATE=true + if [ "${{ matrix.e2e-test }}" == "modulereleasemeta-maintenance-window-with-module-downtime" ]; then + REQUIRE_DOWNTIME=true + else + REQUIRE_DOWNTIME=false + fi + make build-manifests yq eval '(. | select(.kind == "Deployment") | .metadata.name) = "${{ env.ModuleDeploymentNameInNewerVersion }}"' -i template-operator.yaml - ./deploy_moduletemplate.sh ${{ env.ModuleName }} ${{ env.NewerVersion }} + ./deploy_moduletemplate.sh ${{ env.ModuleName }} ${{ env.NewerVersion }} $INCLUDE_DEFAULT_CR $MANDATORY $DEPLOY_MODULETEMPLATE $REQUIRE_DOWNTIME - name: Create and apply ModuleReleaseMeta from the latest release working-directory: template-operator if: ${{ matrix.e2e-test == 'kyma-metrics' || @@ -75,7 +84,8 @@ runs: matrix.e2e-test == 'modulereleasemeta-upgrade-under-deletion' || matrix.e2e-test == 'modulereleasemeta-sync' || matrix.e2e-test == 'module-status-on-skr-connection-lost' || - matrix.e2e-test == 'modulereleasemeta-not-allowed-installation' + matrix.e2e-test == 'modulereleasemeta-not-allowed-installation' || + matrix.e2e-test == 'modulereleasemeta-maintenance-window-with-module-downtime' }} shell: bash run: | diff --git a/.github/workflows/test-e2e-with-modulereleasemeta.yml b/.github/workflows/test-e2e-with-modulereleasemeta.yml index 9cd6b1757d..65c9547a5d 100644 --- a/.github/workflows/test-e2e-with-modulereleasemeta.yml +++ b/.github/workflows/test-e2e-with-modulereleasemeta.yml @@ -67,6 +67,8 @@ jobs: - modulereleasemeta-watch-trigger - modulereleasemeta-not-allowed-installation - labelling + - modulereleasemeta-maintenance-window-with-module-downtime + runs-on: ubuntu-latest timeout-minutes: 20 steps: diff --git a/scripts/tests/deploy_moduletemplate.sh b/scripts/tests/deploy_moduletemplate.sh index f70edce432..5a55bb9368 100755 --- a/scripts/tests/deploy_moduletemplate.sh +++ b/scripts/tests/deploy_moduletemplate.sh @@ -9,6 +9,7 @@ RELEASE_VERSION=$2 INCLUDE_DEFAULT_CR=${3:-true} MANDATORY=${4:-false} DEPLOY_MODULETEMPLATE=${5:-true} +REQUIRES_DOWNTIME=${6:-false} cat < module-config-for-e2e.yaml name: kyma-project.io/module/${MODULE_NAME} @@ -17,6 +18,7 @@ security: sec-scanners-config.yaml manifest: https://localhost:8080/template-operator.yaml repository: https://github.com/kyma-project/template-operator documentation: https://github.com/kyma-project/template-operator/blob/main/README.md +requiresDowntime: ${REQUIRES_DOWNTIME} icons: - name: module-icon link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png diff --git a/tests/e2e/Makefile b/tests/e2e/Makefile index 28cb5ba689..bc54afa9e7 100644 --- a/tests/e2e/Makefile +++ b/tests/e2e/Makefile @@ -171,3 +171,6 @@ modulereleasemeta-not-allowed-installation: labelling: go test -timeout 20m -ginkgo.v -ginkgo.focus "Labelling SKR resources" + +modulereleasemeta-maintenance-window-with-module-downtime: + go test -timeout 20m -ginkgo.v -ginkgo.focus "Maintenance Window With ModuleReleaseMeta and Module Downtime" diff --git a/tests/e2e/modulereleasemeta_maintenance_window_module_downtime_test.go b/tests/e2e/modulereleasemeta_maintenance_window_module_downtime_test.go new file mode 100644 index 0000000000..c6e8972959 --- /dev/null +++ b/tests/e2e/modulereleasemeta_maintenance_window_module_downtime_test.go @@ -0,0 +1,139 @@ +package e2e_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/kyma-project/lifecycle-manager/api/shared" + "github.com/kyma-project/lifecycle-manager/api/v1beta2" + . "github.com/kyma-project/lifecycle-manager/pkg/testutils" + . "github.com/kyma-project/lifecycle-manager/tests/e2e/commontestutils" +) + +var _ = Describe("Maintenance Window With ModuleReleaseMeta and Module Downtime", Ordered, func() { + kyma := NewKymaWithSyncLabel("kyma-sample", ControlPlaneNamespace, v1beta2.DefaultChannel) + kyma.Labels["operator.kyma-project.io/region"] = "europe" + kyma.Spec.SkipMaintenanceWindows = false + /* + Maintenance Windows are defined as such: + region asia: current time - current time + 2 hours + region europe: tomorrow + */ + + module := NewTemplateOperator(v1beta2.DefaultChannel) + moduleCR := NewTestModuleCR(RemoteNamespace) + + InitEmptyKymaBeforeAll(kyma) + CleanupKymaAfterAll(kyma) + + Context("Given SKR Cluster", func() { + It("When Kyma Module is enabled on SKR Kyma CR and Maintenance Window is opt in", func() { + Eventually(EnableModule). + WithContext(ctx). + WithArguments(skrClient, defaultRemoteKymaName, RemoteNamespace, module). + Should(Succeed()) + }) + + It("Then Module CR is deployed", func() { + Eventually(ModuleCRExists). + WithContext(ctx). + WithArguments(skrClient, moduleCR). + Should(Succeed()) + + By("And Module Operator Deployment is deployed") + Eventually(DeploymentIsReady). + WithContext(ctx). + WithArguments(skrClient, ModuleDeploymentNameInOlderVersion, TestModuleResourceNamespace). + Should(Succeed()) + + By("And KCP Kyma CR is in \"Ready\" State") + Eventually(KymaIsInState). + WithContext(ctx). + WithArguments(kyma.GetName(), kyma.GetNamespace(), kcpClient, shared.StateReady). + Should(Succeed()) + }) + + It("When new version requiring downtime is selected in ModuleReleaseMeta,"+ + " but no Maintenance Window is active", func() { + Eventually(UpdateChannelVersionInModuleReleaseMeta). + WithContext(ctx). + WithArguments(kcpClient, module.Name, ControlPlaneNamespace, v1beta2.DefaultChannel, NewerVersion). + Should(Succeed()) + }) + + It("Then Module CR exists", func() { + Eventually(ModuleCRExists). + WithContext(ctx). + WithArguments(skrClient, moduleCR). + Should(Succeed()) + + By("And old Module Operator Deployment still exists") + Consistently(DeploymentIsReady). + WithContext(ctx). + WithArguments(skrClient, ModuleDeploymentNameInOlderVersion, TestModuleResourceNamespace). + Should(Succeed()) + + By("And new Module Operator Deployment is not deployed") + Consistently(DeploymentIsReady). + WithContext(ctx). + WithArguments(skrClient, ModuleDeploymentNameInNewerVersion, TestModuleResourceNamespace). + Should(Equal(ErrNotFound)) + + By("And KCP Kyma CR is in \"Ready\" State") + Eventually(KymaIsInState). + WithContext(ctx). + WithArguments(kyma.GetName(), kyma.GetNamespace(), kcpClient, shared.StateReady). + Should(Succeed()) + }) + + It("When a Maintenance Window is active", func() { + Eventually(UpdateKymaLabel). + WithContext(ctx). + WithArguments(kcpClient, kyma.Name, kyma.Namespace, "operator.kyma-project.io/region", "asia"). + Should(Succeed()) + }) + + It("Then Module CR exists", func() { + Eventually(ModuleCRExists). + WithContext(ctx). + WithArguments(skrClient, moduleCR). + Should(Succeed()) + + By("And old Module Operator Deployment no longer exists") + Eventually(DeploymentIsReady). + WithContext(ctx). + WithArguments(skrClient, ModuleDeploymentNameInOlderVersion, TestModuleResourceNamespace). + Should(Equal(ErrNotFound)) + + By("And new Module Operator Deployment is deployed") + Eventually(DeploymentIsReady). + WithContext(ctx). + WithArguments(skrClient, ModuleDeploymentNameInNewerVersion, TestModuleResourceNamespace). + Should(Succeed()) + + By("And KCP Kyma CR is in \"Ready\" State") + Eventually(KymaIsInState). + WithContext(ctx). + WithArguments(kyma.GetName(), kyma.GetNamespace(), kcpClient, shared.StateReady). + Should(Succeed()) + + By("And Kyma Module Version in Kyma Status is updated") + newModuleTemplateVersion, err := ReadModuleVersionFromModuleTemplate(ctx, kcpClient, module, + kyma.Spec.Channel, ControlPlaneNamespace) + Expect(err).ToNot(HaveOccurred()) + + Eventually(ModuleVersionInKymaStatusIsCorrect). + WithContext(ctx). + WithArguments(kcpClient, kyma.GetName(), kyma.GetNamespace(), module.Name, + newModuleTemplateVersion). + Should(Succeed()) + + By("And Manifest Version is updated") + Eventually(ManifestVersionIsCorrect). + WithContext(ctx). + WithArguments(kcpClient, kyma.GetName(), kyma.GetNamespace(), module.Name, + newModuleTemplateVersion). + Should(Succeed()) + }) + }) +}) diff --git a/versions.yaml b/versions.yaml index 73b46c8fe0..7b4c7dc60c 100644 --- a/versions.yaml +++ b/versions.yaml @@ -1,7 +1,7 @@ # defines the versions of the tools used in the project istio: "1.24.1" k3d: "5.7.4" -modulectl: "1.1.3" +modulectl: "1.1.5" certManager: "1.15.0" k8s: "1.30.3" kustomize: "5.3.0"