Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport to v1.6.x #796

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ jobs:
overwrite: true

e2e-tests:
continue-on-error: true
strategy:
fail-fast: false
matrix:
kubernetes: [ "v1.23.17", "v1.24.15", "v1.25.11", "v1.26.6" ]
replicas: ["1"]
Expand Down
9 changes: 4 additions & 5 deletions .obs/chartfile/operator/templates/channel-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{{ if contains "isv/rancher/elemental" .Values.registryUrl }}
{{ if hasPrefix "registry.opensuse.org" .Values.registryUrl }}
# Unstable channel for isv:Rancher:Elemental OBS projects
# Unstable channel for testing isv:Rancher:Elemental OBS projects
# it is only rendered if the registryUrl value includes a known OBS project reference
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be present also on the final released chart, right?
Not 100% happy that we bring this in the final chart. I see it shouldn't harm, but production ready version should be free of the test references IMHO...
Btw, we can drop it in the marketplace later if needed (maybe even the whole channel-dev 🤔 ... for a later discussion 😄 ).

{{ if and (hasPrefix "registry.opensuse.org" .Values.registryUrl) (contains "isv/rancher/elemental" .Values.registryUrl) }}
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: unstable-channel
name: unstable-testing-channel
namespace: fleet-default
spec:
options:
image: {{ .Values.registryUrl }}/rancher/elemental-unstable-channel:latest
type: custom
{{ end }}
{{ end }}
11 changes: 0 additions & 11 deletions .obs/chartfile/operator/templates/channel.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions .obs/chartfile/operator/templates/channels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ $defChannelName := "" }}
{{ if and .Values.channel .Values.channel.image .Values.channel.tag .Values.channel.name }}
{{ $defChannelName := .Values.channel.name }}
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: {{ .Values.channel.name }}
namespace: fleet-default
spec:
options:
image: {{ .Values.channel.image }}:{{ .Values.channel.tag }}
type: custom
{{ end }}

# Keep pre-existing channels managed by Helm if they do not match with the current default
# this way if an upgrade introduces a new channel any pre-existing channel managed by Helm is not deleted
{{ range $index, $channel := (lookup "elemental.cattle.io/v1beta1" "ManagedOSVersionChannel" "fleet-default" "").items }}
{{ if and (eq (index $channel.metadata.labels "app.kubernetes.io/managed-by") "Helm") (ne $channel.metadata.name $defChannelName) }}
---
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: {{ $channel.metadata.name }}
namespace: fleet-default
spec:
options:
image: {{ $channel.spec.options.image }}
type: custom
{{ end }}
{{ end }}
3 changes: 1 addition & 2 deletions controllers/managedosversionchannel_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ var _ = Describe("reconcile managed os version channel", func() {
// Re-sync is triggered to interval
res, err = r.Reconcile(ctx, reconcile.Request{NamespacedName: name})
Expect(err).ToNot(HaveOccurred())
Expect(res.RequeueAfter).To(BeNumerically("<", 1*time.Minute))
Expect(res.RequeueAfter).To(BeNumerically(">", 59*time.Second))
Expect(res.RequeueAfter).To(BeNumerically("~", 59*time.Second, 1*time.Minute))
})

It("should reconcile managed os version channel object without a type", func() {
Expand Down
103 changes: 103 additions & 0 deletions tests/e2e/downgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright © 2022 - 2024 SUSE LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e_test

import (
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
elementalv1 "github.com/rancher/elemental-operator/api/v1beta1"
"github.com/rancher/elemental-operator/tests/e2e/config"
"sigs.k8s.io/controller-runtime/pkg/client"

kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl"
)

const stableCRDSChart = "oci://registry.suse.com/rancher/elemental-operator-crds-chart"
const stableChart = "oci://registry.suse.com/rancher/elemental-operator-chart"

var _ = Describe("Elemental Operator downgrade/upgrade test", func() {
var k *kubectl.Kubectl
var downgradeCfg config.E2EConfig
var channelName string
var managedByLabel map[string]string

It("downgrades to latest stable version", func() {
k = kubectl.New()
downgradeCfg = *e2eCfg
downgradeCfg.CRDsChart = stableCRDSChart
downgradeCfg.Chart = stableChart
channelName = ""
managedByLabel = map[string]string{
"app.kubernetes.io/managed-by": "Helm",
}

Expect(isOperatorInstalled(k)).To(BeTrue())

By("Uninstall Elemental Operator first before downgrading CRDs chart", func() {
Expect(kubectl.RunHelmBinaryWithCustomErr(
"uninstall", operatorName,
"--namespace", operatorNamespace,
"--wait",
)).To(Succeed())
})

By("Install the new Elemental Operator", func() {
deployOperator(k, &downgradeCfg)
})

By("Check it gets a default channel and syncs ManagedOSVersions", func() {
Eventually(func() string {
channels := &elementalv1.ManagedOSVersionChannelList{}
err := cl.List(ctx, channels, client.InNamespace(fleetDefaultNamespace), client.MatchingLabels(managedByLabel))
if err == nil {
// After uninstalling Operator and reinstalling it there should be only a single channel managed by Helm
Expect(len(channels.Items)).To(Equal(1))
channelName = channels.Items[0].Name
}
return channelName
}, 10*time.Second, 1*time.Second).ShouldNot(BeEmpty())

Eventually(func() int {
mOSes := &elementalv1.ManagedOSVersionList{}
err := cl.List(ctx, mOSes, client.InNamespace(fleetDefaultNamespace), client.MatchingLabels(map[string]string{
elementalv1.ElementalManagedOSVersionChannelLabel: channelName,
}))
if err == nil {
return len(mOSes.Items)
}
return 0
}, 2*time.Minute, 2*time.Second).Should(BeNumerically(">", 0))
})

By("Upgrading Elemental Operator to testing version", func() {
deployOperator(k, e2eCfg)
})

By("Check we still keep the previous default channel managed by Helm", func() {
Eventually(func() error {
ch := &elementalv1.ManagedOSVersionChannel{}
err := cl.Get(ctx, client.ObjectKey{
Name: channelName,
Namespace: fleetDefaultNamespace,
}, ch)
return err
}, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred())
})
})
})
12 changes: 8 additions & 4 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,14 @@ func getElementalOperatorLogs() {
)).To(Succeed())

for _, pod := range podList.Items {
for _, container := range pod.Spec.Containers {
output, err := kubectl.Run("logs", pod.Name, "-c", container.Name, "-n", pod.Namespace)
Expect(err).ToNot(HaveOccurred())
Expect(os.WriteFile(filepath.Join(e2eCfg.ArtifactsDir, pod.Name+"-"+container.Name+".log"), []byte(output), 0644)).To(Succeed())
if pod.Status.Phase == corev1.PodRunning {
for _, cStatus := range pod.Status.ContainerStatuses {
if cStatus.Started != nil && *cStatus.Started {
output, err := kubectl.Run("logs", pod.Name, "-c", cStatus.Name, "-n", pod.Namespace)
Expect(err).ToNot(HaveOccurred())
Expect(os.WriteFile(filepath.Join(e2eCfg.ArtifactsDir, pod.Name+"-"+cStatus.Name+".log"), []byte(output), 0644)).To(Succeed())
}
}
}
}
}