Skip to content

Commit

Permalink
test: Add Concept for Maintenance Window with Module Downtime E2E Test (
Browse files Browse the repository at this point in the history
kyma-project#2187)

* test: Add Concept for Maintenance Window with Module Downtime E2E Test

* fix: Add Test to E2E Matrix

* chore: Log Maintenance Window Policy

* fix: Replace Eventually with Consistently

* chore: Use Latest Modulectl Release

* refactor: Add Trailing Empty Line

Co-authored-by: Christoph Schwägerl <[email protected]>

* refactor: Remove Extra Build Step

* refactor: Remove Unnecessary Quotes

---------

Co-authored-by: Christoph Schwägerl <[email protected]>
  • Loading branch information
LeelaChacha and c-pius authored Jan 17, 2025
1 parent c087c13 commit 0301f08
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .github/actions/deploy-lifecycle-manager-e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > ./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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand All @@ -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: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-e2e-with-modulereleasemeta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions scripts/tests/deploy_moduletemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RELEASE_VERSION=$2
INCLUDE_DEFAULT_CR=${3:-true}
MANDATORY=${4:-false}
DEPLOY_MODULETEMPLATE=${5:-true}
REQUIRES_DOWNTIME=${6:-false}

cat <<EOF > module-config-for-e2e.yaml
name: kyma-project.io/module/${MODULE_NAME}
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
139 changes: 139 additions & 0 deletions tests/e2e/modulereleasemeta_maintenance_window_module_downtime_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})
})
2 changes: 1 addition & 1 deletion versions.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 0301f08

Please sign in to comment.