Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
Fix Dockerfile entrypoint
Fix some tests referring to old structs

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Jul 11, 2022
1 parent 66f27eb commit 74301fa
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 59 deletions.
1 change: 0 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ jobs:
go-version: '^1.17'
- name: Deps
run: |
ip a
make test_deps
- uses: engineerd/[email protected]
with:
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ COPY cmd /src/cmd
# Set arg/env after go mod download, otherwise we invalidate the cached layers due to the commit changing easily
ARG VERSION=0.0.0
ENV VERSION=${VERSION}
RUN go build -ldflags "-extldflags -static -s -X 'github.com/rancher/elemental-operator/version.Version=$(VERSION)'" -o /usr/sbin/rancheros-operator
RUN go build -ldflags "-extldflags -static -s -X github.com/rancher/elemental-operator/version.Version=$VERSION" -o /usr/sbin/elemental-operator

FROM scratch as ros-operator
COPY --from=build /usr/sbin/rancheros-operator /usr/sbin/rancheros-operator
FROM scratch as elemental-operator
COPY --from=build /usr/sbin/elemental-operator /usr/sbin/elemental-operator
ENTRYPOINT ["/usr/sbin/elemental-operator"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" )
TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT}
REPO?=rancher/elemental-operator
REPO?=rancher/elemental-operator-ci
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CHART?=$(shell find $(ROOT_DIR) -type f -name "elemental-operator*.tgz" -print)
CHART_VERSION?=$(subst v,,$(GIT_TAG))
Expand Down
16 changes: 6 additions & 10 deletions tests/catalog/machineregistration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ limitations under the License.

package catalog

import v1beta1 "github.com/rancher/elemental-operator/pkg/apis/elemental.cattle.io/v1beta1"

type MachineRegistration 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 {
CloudConfig map[string]interface{} `json:"cloudConfig" yaml:"cloudConfig"`
} `json:"spec" yaml:"spec"`
Spec v1beta1.MachineRegistrationSpec `json:"spec" yaml:"spec"`
}

func NewMachineRegistration(name string, cloudConfig map[string]interface{}) *MachineRegistration {
func NewMachineRegistration(name string, spec v1beta1.MachineRegistrationSpec) *MachineRegistration {
return &MachineRegistration{
APIVersion: "rancheros.cattle.io/v1",
APIVersion: "elemental.cattle.io/v1beta1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Kind: "MachineRegistration",
Spec: struct {
CloudConfig map[string]interface{} "json:\"cloudConfig\" yaml:\"cloudConfig\""
}{
CloudConfig: cloudConfig,
},
Spec: spec,
}
}
14 changes: 7 additions & 7 deletions tests/catalog/managedosimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ type ManagedOSImage struct {
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"`
Targets []map[string]interface{} `json:"clusterTargets" yaml:"clusterTargets"`
}
}

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

return &ManagedOSImage{
APIVersion: "rancheros.cattle.io/v1",
APIVersion: "elemental.cattle.io/v1beta1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Expand All @@ -60,20 +60,20 @@ func NewManagedOSImage(name string, clusterTargets []map[string]interface{}, mos
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"`
Targets []map[string]interface{} `json:"clusterTargets" yaml:"clusterTargets"`
}{
OSImage: mosImage,
ManagedOSVersionName: mosVersionName,
Cordon: &cordon,
ClusterTargets: clusterTargets,
Targets: targets,
},
}
}

func DrainOSImage(name string, managedOSVersion string, drainSpec *DrainSpec) *ManagedOSImage {
cordon := false
return &ManagedOSImage{
APIVersion: "rancheros.cattle.io/v1",
APIVersion: "elemental.cattle.io/v1beta1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Expand All @@ -83,7 +83,7 @@ func DrainOSImage(name string, managedOSVersion string, drainSpec *DrainSpec) *M
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"`
Targets []map[string]interface{} `json:"clusterTargets" yaml:"clusterTargets"`
}{
Cordon: &cordon,
ManagedOSVersionName: managedOSVersion,
Expand Down
2 changes: 1 addition & 1 deletion tests/catalog/managedosversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ContainerSpec struct {

func NewManagedOSVersion(name string, version string, minVersion string, metadata map[string]interface{}, upgradeC *ContainerSpec) *ManagedOSVersion {
return &ManagedOSVersion{
APIVersion: "rancheros.cattle.io/v1",
APIVersion: "elemental.cattle.io/v1beta1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Expand Down
2 changes: 1 addition & 1 deletion tests/catalog/managedosversionchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ManagedOSVersionChannel struct {

func NewManagedOSVersionChannel(name string, t string, options map[string]interface{}, upgradeContainer *ContainerSpec) *ManagedOSVersionChannel {
return &ManagedOSVersionChannel{
APIVersion: "rancheros.cattle.io/v1",
APIVersion: "elemental.cattle.io/v1beta1",
Metadata: struct {
Name string "json:\"name\" yaml:\"name\""
}{Name: name},
Expand Down
27 changes: 8 additions & 19 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ package e2e_test
import (
"bytes"
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl"
"github.com/rancher/elemental-operator/tests/catalog"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl"
"github.com/rancher/elemental-operator/tests/catalog"
)

var (
Expand All @@ -54,7 +52,7 @@ func isOperatorInstalled(k *kubectl.Kubectl) bool {
}

func deployOperator(k *kubectl.Kubectl) {
By("Deploying ros-operator chart", func() {
By("Deploying elemental-operator chart", func() {
err := kubectl.RunHelmBinaryWithCustomErr(
"-n", "cattle-elemental-operator-system", "install", "--create-namespace", "elemental-operator", chart)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -69,15 +67,6 @@ func deployOperator(k *kubectl.Kubectl) {
err = k.WaitForNamespaceWithPod("cattle-elemental-operator-system", "app=elemental-operator")
Expect(err).ToNot(HaveOccurred())

Eventually(func() string {
str, _ := kubectl.Run("logs", "-n", "cattle-elemental-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 @@ -114,7 +103,7 @@ var _ = BeforeSuite(func() {

chart = os.Getenv("CHART")
if chart == "" && !isOperatorInstalled(k) {
Fail("No CHART provided, a ros operator helm chart is required to run e2e tests")
Fail("No CHART provided, a elemental operator helm chart is required to run e2e tests")
} else if isOperatorInstalled(k) {
//
// Upgrade/delete of operator only goes here
Expand All @@ -128,7 +117,7 @@ var _ = BeforeSuite(func() {

deployOperator(k)

// Somehow rancher needs to be restarted after a ros-operator upgrade
// Somehow rancher needs to be restarted after a elemental-operator upgrade
// to get machineregistration working
pods, err := k.GetPodNames("cattle-system", "")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -155,7 +144,7 @@ var _ = BeforeSuite(func() {
}
return false
}
By("Deploying ros-operator chart dependencies", func() {
By("Deploying elemental-operator chart dependencies", func() {
By("installing nginx", func() {
if installed("ingress-nginx") {
By("already installed")
Expand Down
15 changes: 4 additions & 11 deletions tests/e2e/machineregistration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
http "github.com/rancher-sandbox/ele-testhelpers/http"
kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl"

"github.com/rancher/elemental-operator/pkg/apis/elemental.cattle.io/v1beta1"
"github.com/rancher/elemental-operator/pkg/installer"
"github.com/rancher/elemental-operator/tests/catalog"
)

Expand All @@ -37,17 +39,8 @@ var _ = Describe("MachineRegistration e2e tests", func() {
})

It("creates a machine registration resource and a URL attaching CA certificate", func() {
mr := catalog.NewMachineRegistration("machine-registration", map[string]interface{}{
"install": map[string]string{"device": "/dev/vda"},
"rancheros": map[string]interface{}{"install": map[string]string{"isoUrl": "https://something.example.com"}},
"users": []map[string]string{
{
"name": "root",
"passwd": "root",
},
},
})

spec := v1beta1.MachineRegistrationSpec{Install: &installer.Install{Device: "/dev/vda", ISO: "https://something.example.com"}}
mr := catalog.NewMachineRegistration("machine-registration", spec)
Eventually(func() error {
return k.ApplyYAML("fleet-default", "machine-registration", mr)
}, 2*time.Minute, 2*time.Second).ShouldNot(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/managedosimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = Describe("ManagedOSImage e2e tests", func() {

EventuallyWithOffset(1, func() error {
return k.ApplyYAML("fleet-default", osVersion, ov)
}, 2*time.Minute, 2*time.Second).ShouldNot(HaveOccurred())
}, 1*time.Minute, 2*time.Second).ShouldNot(HaveOccurred())

ui := catalog.NewManagedOSImage(
osImage,
Expand All @@ -94,7 +94,7 @@ var _ = Describe("ManagedOSImage e2e tests", func() {

EventuallyWithOffset(1, func() error {
return k.ApplyYAML("fleet-default", osImage, ui)
}, 2*time.Minute, 2*time.Second).ShouldNot(HaveOccurred())
}, 1*time.Minute, 2*time.Second).ShouldNot(HaveOccurred())

EventuallyWithOffset(1, func() string {
r, err := kubectl.GetData("fleet-default", "bundle", "mos-update-osversion", `jsonpath={.spec.resources[*].content}`)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/managedosversionchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("ManagedOSVersionChannel e2e tests", func() {
)
})

It("creates a list of ManagedOSVersion from a JSON server", func() {
It("creates a list of ManagedOSVersion from a JSON server", Focus, func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("ManagedOSVersionChannel e2e tests", func() {
}

return string(r)
}, 1*time.Minute, 2*time.Second).Should(
}, 5*time.Minute, 2*time.Second).Should(
Equal("registry.com/repository/image:v1"),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func checkUpgradePod(k *kubectl.Kubectl, env, image, command, args, mm types.Gom
cattleNamespace,
"upgrade.cattle.io/controller=system-upgrade-controller",
3*time.Minute, 2*time.Second,
ContainElement(ContainSubstring("apply-os-upgrader-on-ros-e2e-control-plane-with")),
ContainElement(ContainSubstring("apply-os-upgrader-on-operator-e2e-control-plane-with")),
)

podName := upgradePod(k)
Expand Down

0 comments on commit 74301fa

Please sign in to comment.