Skip to content

Commit

Permalink
tests: Add upgrades e2e test
Browse files Browse the repository at this point in the history
The test is trying to run an upgrade on the cluster, checking the logs
of the pod created by system-upgrade-controller which should contain
traces of elemental-cli being called.

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
  • Loading branch information
mudler committed Apr 19, 2022
1 parent 8d4aeba commit ff7c6d5
Show file tree
Hide file tree
Showing 7 changed files with 507 additions and 21 deletions.
1 change: 0 additions & 1 deletion pkg/controllers/managedos/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"

fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/sirupsen/logrus"

osv1 "github.com/rancher-sandbox/rancheros-operator/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher-sandbox/rancheros-operator/pkg/clients"
Expand Down
50 changes: 47 additions & 3 deletions tests/catalog/managedosimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,78 @@ limitations under the License.

package catalog

import (
"time"
)

type DrainSpec struct {
Timeout *time.Duration `json:"timeout,omitempty" yaml:"timeout"`
GracePeriod *int32 `json:"gracePeriod,omitempty" yaml:"gracePeriod"`
DeleteLocalData *bool `json:"deleteLocalData,omitempty" yaml:"deleteLocalData"`
IgnoreDaemonSets *bool `json:"ignoreDaemonSets,omitempty" yaml:"ignoreDaemonSets"`
Force bool `json:"force,omitempty" yaml:"force"`
DisableEviction bool `json:"disableEviction,omitempty" yaml:"disableEviction"`
SkipWaitForDeleteTimeout int `json:"skipWaitForDeleteTimeout,omitempty" yaml:"skipWaitForDeleteTimeout"`
}

type ManagedOSImage struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
Kind string `json:"kind" yaml:"kind"`
Metadata struct {
Name string `json:"name" yaml:"name"`
} `json:"metadata" yaml:"metadata"`

Spec struct {
Cordon *bool `json:"cordon,omitempty" yaml:"cordon"`
Drain *DrainSpec `json:"drain,omitempty" yaml:"drain"`
OSImage string `json:"osImage" yaml:"osImage"`
ManagedOSVersionName string `json:"managedOSVersionName" yaml:"managedOSVersionName"`
ClusterTargets []map[string]interface{} `json:"clusterTargets" yaml:"clusterTargets"`
}
}

func NewManagedOSImage(name string, clusterTargets []map[string]interface{}, mosImage string, mosVersionName string) *ManagedOSImage {
cordon := false

return &ManagedOSImage{
APIVersion: "rancheros.cattle.io/v1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Kind: "ManagedOSImage",
Spec: struct {
OSImage string "json:\"osImage\" yaml:\"osImage\""
ManagedOSVersionName string "json:\"managedOSVersionName\" yaml:\"managedOSVersionName\""
ClusterTargets []map[string]interface{} "json:\"clusterTargets\" yaml:\"clusterTargets\""
Cordon *bool `json:"cordon,omitempty" yaml:"cordon"`
Drain *DrainSpec `json:"drain,omitempty" yaml:"drain"`
OSImage string `json:"osImage" yaml:"osImage"`
ManagedOSVersionName string `json:"managedOSVersionName" yaml:"managedOSVersionName"`
ClusterTargets []map[string]interface{} `json:"clusterTargets" yaml:"clusterTargets"`
}{
OSImage: mosImage,
ManagedOSVersionName: mosVersionName,
Cordon: &cordon,
ClusterTargets: clusterTargets,
},
}
}

func DrainOSImage(name string, managedOSVersion string, drainSpec *DrainSpec) *ManagedOSImage {
cordon := false
return &ManagedOSImage{
APIVersion: "rancheros.cattle.io/v1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Kind: "ManagedOSImage",
Spec: struct {
Cordon *bool `json:"cordon,omitempty" yaml:"cordon"`
Drain *DrainSpec `json:"drain,omitempty" yaml:"drain"`
OSImage string `json:"osImage" yaml:"osImage"`
ManagedOSVersionName string `json:"managedOSVersionName" yaml:"managedOSVersionName"`
ClusterTargets []map[string]interface{} `json:"clusterTargets" yaml:"clusterTargets"`
}{
Cordon: &cordon,
ManagedOSVersionName: managedOSVersion,
Drain: drainSpec,
},
}
}
2 changes: 1 addition & 1 deletion tests/catalog/managedosversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ManagedOSVersion struct {

type ContainerSpec struct {
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Command string `json:"command,omitempty" yaml:"command,omitempty"`
Command []string `json:"command,omitempty" yaml:"command,omitempty"`
Args []string `json:"args,omitempty" yaml:"args,omitempty"`
}

Expand Down
9 changes: 5 additions & 4 deletions tests/catalog/managedosversionchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package catalog
type ManagedOSVersionChannelSpec struct {
Type string `json:"type" yaml:"type"`
Options map[string]interface{} `json:"options" yaml:"options"`
UpgradeContainer ContainerSpec `json:"upgradeContainer" yaml:"upgradeContainer"`
UpgradeContainer *ContainerSpec `json:"upgradeContainer,omitempty" yaml:"upgradeContainer"`
}

type ManagedOSVersionChannel struct {
Expand All @@ -31,16 +31,17 @@ type ManagedOSVersionChannel struct {
Spec ManagedOSVersionChannelSpec
}

func NewManagedOSVersionChannel(name string, t string, options map[string]interface{}) *ManagedOSVersionChannel {
func NewManagedOSVersionChannel(name string, t string, options map[string]interface{}, upgradeContainer *ContainerSpec) *ManagedOSVersionChannel {
return &ManagedOSVersionChannel{
APIVersion: "rancheros.cattle.io/v1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Kind: "ManagedOSVersionChannel",
Spec: ManagedOSVersionChannelSpec{
Type: t,
Options: options,
Type: t,
Options: options,
UpgradeContainer: upgradeContainer,
},
}
}
62 changes: 50 additions & 12 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ limitations under the License.
package e2e_test

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -56,9 +62,22 @@ func deployOperator(k *kubectl.Kubectl) {
err = k.WaitForPod("cattle-rancheros-operator-system", "app=rancheros-operator", "rancheros-operator")
Expect(err).ToNot(HaveOccurred())

pods, err := k.GetPodNames("cattle-rancheros-operator-system", "app=rancheros-operator")
Expect(err).ToNot(HaveOccurred())
Expect(len(pods)).To(Equal(1))

err = k.WaitForNamespaceWithPod("cattle-rancheros-operator-system", "app=rancheros-operator")
Expect(err).ToNot(HaveOccurred())

Eventually(func() string {
str, _ := kubectl.Run("logs", "-n", "cattle-rancheros-operator-system", pods[0])
fmt.Println(str)
return str
}, 5*time.Minute, 2*time.Second).Should(
And(
ContainSubstring("Starting management.cattle.io/v3, Kind=Setting controller"),
))

err = k.ApplyYAML("", "server-url", catalog.NewSetting("server-url", "env", fmt.Sprintf("%s.%s", externalIP, magicDNS)))
Expect(err).ToNot(HaveOccurred())
})
Expand Down Expand Up @@ -88,6 +107,11 @@ var _ = BeforeSuite(func() {
bridgeIP = "172.17.0.1"
}

if os.Getenv("NO_SETUP") != "" {
By("No setup")
return
}

chart = os.Getenv("ROS_CHART")
if chart == "" && !isOperatorInstalled(k) {
Fail("No ROS_CHART provided, a ros operator helm chart is required to run e2e tests")
Expand All @@ -99,7 +123,7 @@ var _ = BeforeSuite(func() {
err := kubectl.DeleteNamespace("cattle-rancheros-operator-system")
Expect(err).ToNot(HaveOccurred())

err = k.WaitNamespacePodsDelete("cattle-rancheros-operator-system")
err = k.WaitForNamespaceDelete("cattle-rancheros-operator-system")
Expect(err).ToNot(HaveOccurred())

deployOperator(k)
Expand All @@ -119,11 +143,6 @@ var _ = BeforeSuite(func() {
return
}

if os.Getenv("NO_SETUP") != "" {
By("No setup")
return
}

if isOperatorInstalled(k) {
By("rancher-os already deployed, skipping setup")
return
Expand All @@ -150,12 +169,6 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())
})

By("installing system-upgrade-controller", func() {
// https://github.com/rancher/system-upgrade-controller/releases/download/v0.9.1/system-upgrade-controller.yaml\
err := kubectl.Apply("system-upgrade", "https://github.com/rancher/system-upgrade-controller/releases/download/v0.9.1/system-upgrade-controller.yaml")
Expect(err).ToNot(HaveOccurred())
})

By("installing cert-manager", func() {
if installed("cert-manager") {
By("already installed")
Expand Down Expand Up @@ -202,6 +215,31 @@ var _ = BeforeSuite(func() {
err = k.WaitForNamespaceWithPod("cattle-fleet-local-system", "app=fleet-agent")
Expect(err).ToNot(HaveOccurred())
})

By("installing system-upgrade-controller", func() {

resp, err := http.Get("https://github.com/rancher/system-upgrade-controller/releases/download/v0.9.1/system-upgrade-controller.yaml")
Expect(err).ToNot(HaveOccurred())
defer resp.Body.Close()
data := bytes.NewBuffer([]byte{})

_, err = io.Copy(data, resp.Body)
Expect(err).ToNot(HaveOccurred())

// It needs to look over cattle-system ns to be functional
toApply := strings.ReplaceAll(data.String(), "namespace: system-upgrade", "namespace: cattle-system")

temp, err := ioutil.TempFile("", "temp")
Expect(err).ToNot(HaveOccurred())

defer os.RemoveAll(temp.Name())
err = ioutil.WriteFile(temp.Name(), []byte(toApply), os.ModePerm)
Expect(err).ToNot(HaveOccurred())

err = kubectl.Apply("cattle-system", temp.Name())
Expect(err).ToNot(HaveOccurred())
})

})

deployOperator(k)
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/managedosversionchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import (
var _ = Describe("ManagedOSVersionChannel e2e tests", func() {
var k *kubectl.Kubectl

AfterEach(func() {
err := k.Delete("managedosversionchannel", "--all", "--force", "--wait", "-n", "fleet-default")
Expect(err).ShouldNot(HaveOccurred())
})

Context("Create ManagedOSVersions", func() {
BeforeEach(func() {
k = kubectl.New()
Expand All @@ -48,6 +53,7 @@ var _ = Describe("ManagedOSVersionChannel e2e tests", func() {
"invalid",
"",
map[string]interface{}{"uri": "http://" + bridgeIP + ":9999"},
nil,
)

err := k.ApplyYAML("fleet-default", "invalid", ui)
Expand Down Expand Up @@ -109,6 +115,7 @@ var _ = Describe("ManagedOSVersionChannel e2e tests", func() {
"testchannel",
"json",
map[string]interface{}{"uri": "http://" + bridgeIP + ":9999"},
nil,
)

err = k.ApplyYAML("fleet-default", "testchannel", ui)
Expand Down Expand Up @@ -204,6 +211,7 @@ var _ = Describe("ManagedOSVersionChannel e2e tests", func() {
"outputFile": "/output/data", // This defaults to /data/output
"args": []string{fmt.Sprintf("echo '%s' > /output/data", string(b))},
},
nil,
)

err = k.ApplyYAML("fleet-default", "testchannel2", ui)
Expand Down
Loading

0 comments on commit ff7c6d5

Please sign in to comment.