Skip to content

Commit

Permalink
test commit for testing with dev env
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Adil Ghaffar <muhammad.adil.ghaffar@est.tech>
  • Loading branch information
adilGhaffarDev committed Aug 12, 2024
1 parent a8629bc commit 8d08228
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 67 deletions.
4 changes: 2 additions & 2 deletions scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ source "${REPO_ROOT}/scripts/environment.sh"
# Clone dev-env repo
sudo mkdir -p ${WORKING_DIR}
sudo chown "${USER}":"${USER}" ${WORKING_DIR}
M3_DEV_ENV_REPO="https://github.com/metal3-io/metal3-dev-env.git"
M3_DEV_ENV_BRANCH=main
M3_DEV_ENV_REPO="https://github.com/Nordix/metal3-dev-env.git"
M3_DEV_ENV_BRANCH=uplift-k8s-1.31.0-rc.0/adil
M3_DEV_ENV_PATH="${M3_DEV_ENV_PATH:-${WORKING_DIR}/metal3-dev-env}"
clone_repo "${M3_DEV_ENV_REPO}" "${M3_DEV_ENV_BRANCH}" "${M3_DEV_ENV_PATH}"

Expand Down
19 changes: 19 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,25 @@ func ListNodes(ctx context.Context, c client.Client) {
logTable("Listing Nodes", rows)
}

func CreateNewM3MachineTemplate(ctx context.Context, namespace string, newM3MachineTemplateName string, m3MachineTemplateName string, clusterClient client.Client, imageURL string, imageChecksum string) {
checksumType := "sha256"
imageFormat := "raw"

m3MachineTemplate := infrav1.Metal3MachineTemplate{}
Expect(clusterClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: m3MachineTemplateName}, &m3MachineTemplate)).To(Succeed())

newM3MachineTemplate := m3MachineTemplate.DeepCopy()
cleanObjectMeta(&newM3MachineTemplate.ObjectMeta)

newM3MachineTemplate.Spec.Template.Spec.Image.URL = imageURL
newM3MachineTemplate.Spec.Template.Spec.Image.Checksum = imageChecksum
newM3MachineTemplate.Spec.Template.Spec.Image.DiskFormat = &imageFormat
newM3MachineTemplate.Spec.Template.Spec.Image.ChecksumType = &checksumType
newM3MachineTemplate.ObjectMeta.Name = newM3MachineTemplateName

Expect(clusterClient.Create(ctx, newM3MachineTemplate)).To(Succeed(), "Failed to create new Metal3MachineTemplate")
}

type WaitForNumInput struct {
Client client.Client
Options []client.ListOption
Expand Down
45 changes: 21 additions & 24 deletions test/e2e/config/e2e_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ providers:
- name: cluster-api
type: CoreProvider
versions:
- name: "v1.8.0" # supported release in the v1beta1 series
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.0-rc.0/core-components.yaml"
type: "url"
contract: v1beta1
replacements:
- old: --metrics-addr=127.0.0.1:8080
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.8/metadata.yaml"
- name: "{go://sigs.k8s.io/cluster-api@v1.7}"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/{go://sigs.k8s.io/cluster-api@v1.7}/core-components.yaml"
type: "url"
Expand All @@ -35,18 +44,18 @@ providers:
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.6/metadata.yaml"
- name: "{go://sigs.k8s.io/cluster-api@v1.5}"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/{go://sigs.k8s.io/cluster-api@v1.5}/core-components.yaml"
- name: kubeadm
type: BootstrapProvider
versions:
- name: "v1.8.0" # supported release in the v1beta1 series
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.0-rc.0/bootstrap-components.yaml"
type: "url"
contract: v1beta1
replacements:
- old: --metrics-addr=127.0.0.1:8080
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.5/metadata.yaml"
- name: kubeadm
type: BootstrapProvider
versions:
- sourcePath: "../data/shared/v1.8/metadata.yaml"
- name: "{go://sigs.k8s.io/cluster-api@v1.7}"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/{go://sigs.k8s.io/cluster-api@v1.7}/bootstrap-components.yaml"
type: "url"
Expand All @@ -65,18 +74,18 @@ providers:
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.6/metadata.yaml"
- name: "{go://sigs.k8s.io/cluster-api@v1.5}"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/{go://sigs.k8s.io/cluster-api@v1.5}/bootstrap-components.yaml"
- name: kubeadm
type: ControlPlaneProvider
versions:
- name: "v1.8.0" # supported release in the v1beta1 series
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.0-rc.0/control-plane-components.yaml"
type: "url"
contract: v1beta1
replacements:
- old: --metrics-addr=127.0.0.1:8080
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.5/metadata.yaml"
- name: kubeadm
type: ControlPlaneProvider
versions:
- sourcePath: "../data/shared/v1.8/metadata.yaml"
- name: "{go://sigs.k8s.io/cluster-api@v1.7}"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/{go://sigs.k8s.io/cluster-api@v1.7}/control-plane-components.yaml"
type: "url"
Expand All @@ -95,19 +104,7 @@ providers:
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.6/metadata.yaml"
- name: "{go://sigs.k8s.io/cluster-api@v1.5}"
value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/{go://sigs.k8s.io/cluster-api@v1.5}/control-plane-components.yaml"
type: "url"
contract: v1beta1
replacements:
- old: --metrics-addr=127.0.0.1:8080
new: --metrics-addr=:8080
files:
- sourcePath: "../data/shared/v1.5/metadata.yaml"
# https://proxy.golang.org/sigs.k8s.io/cluster-api/@v/list


# https://proxy.golang.org/github.com/metal3-io/cluster-api-provider-metal3/@v/list
- name: metal3
type: InfrastructureProvider
versions:
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/data/shared/v1.8/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# maps release series of major.minor to cluster-api contract version
# the contract version may change between minor or major versions, but *not*
# between patch versions.
#
# update this file only when a new major or minor version is released
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
kind: Metadata
releaseSeries:
- major: 1
minor: 8
contract: v1beta1
- major: 1
minor: 7
contract: v1beta1
- major: 1
minor: 6
contract: v1beta1
- major: 1
minor: 5
contract: v1beta1
- major: 1
minor: 4
contract: v1beta1
- major: 1
minor: 3
contract: v1beta1
- major: 1
minor: 2
contract: v1beta1
- major: 1
minor: 1
contract: v1beta1
- major: 1
minor: 0
contract: v1beta1
44 changes: 26 additions & 18 deletions test/e2e/ip_reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
bmov1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/types"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
Expand Down Expand Up @@ -116,24 +115,23 @@ func IPReuse(ctx context.Context, inputGetter func() IPReuseInput) {
Expect(machineDeployments).To(HaveLen(1), "Expected exactly 1 MachineDeployment")
md := machineDeployments[0]

// Download node image
Byf("Download image %s", kubernetesVersion)
imageURL, imageChecksum := EnsureImage(kubernetesVersion)

By("Create new worker Metal3MachineTemplate with upgraded image to boot")
m3MachineTemplateName := md.Spec.Template.Spec.InfrastructureRef.Name
newM3MachineTemplateName := fmt.Sprintf("%s-new", m3MachineTemplateName)
CreateNewM3MachineTemplate(ctx, input.Namespace, newM3MachineTemplateName, m3MachineTemplateName, managementClusterClient, imageURL, imageChecksum)

Byf("Update MachineDeployment maxUnavailable to number of workers and k8s version from %s to %s", fromK8sVersion, kubernetesVersion)
patch := []byte(fmt.Sprintf(`{
"spec": {
"strategy": {
"rollingUpdate": {
"maxSurge": 0,
"maxUnavailable": 3
}
},
"template": {
"spec": {
"version": "%s"
}
}
}
}`, kubernetesVersion))
err = managementClusterClient.Patch(ctx, md, client.RawPatch(types.MergePatchType, patch))
Expect(err).ToNot(HaveOccurred(), "Failed to patch MachineDeployment")
helper, err := patch.NewHelper(md, managementClusterClient)
Expect(err).NotTo(HaveOccurred())
md.Spec.Template.Spec.InfrastructureRef.Name = newM3MachineTemplateName
md.Spec.Template.Spec.Version = &kubernetesVersion
md.Spec.Strategy.RollingUpdate.MaxSurge.IntVal = 0
md.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal = 3
Expect(helper.Patch(ctx, md)).To(Succeed())

Byf("Wait until %d BMH(s) in deprovisioning state", 3)
WaitForNumBmhInState(ctx, bmov1alpha1.StateDeprovisioning, WaitForNumInput{
Expand All @@ -143,6 +141,11 @@ func IPReuse(ctx context.Context, inputGetter func() IPReuseInput) {
Intervals: input.E2EConfig.GetIntervals(input.SpecName, "wait-bmh-deprovisioning"),
})

ListBareMetalHosts(ctx, managementClusterClient, client.InNamespace(input.Namespace))
ListMetal3Machines(ctx, managementClusterClient, client.InNamespace(input.Namespace))
ListMachines(ctx, managementClusterClient, client.InNamespace(input.Namespace))
ListNodes(ctx, targetClusterClient)

Byf("Wait until all %d machine(s) become(s) running", 4)
WaitForNumMachinesInState(ctx, clusterv1.MachinePhaseRunning, WaitForNumInput{
Client: managementClusterClient,
Expand All @@ -151,6 +154,11 @@ func IPReuse(ctx context.Context, inputGetter func() IPReuseInput) {
Intervals: input.E2EConfig.GetIntervals(input.SpecName, "wait-machine-running"),
})

ListBareMetalHosts(ctx, managementClusterClient, client.InNamespace(input.Namespace))
ListMetal3Machines(ctx, managementClusterClient, client.InNamespace(input.Namespace))
ListMachines(ctx, managementClusterClient, client.InNamespace(input.Namespace))
ListNodes(ctx, targetClusterClient)

By("Get the IPPools in the cluster")
baremetalv4Pool, provisioningPool = GetIPPools(ctx, managementClusterClient, input.ClusterName, input.Namespace)
Expect(baremetalv4Pool).To(HaveLen(1))
Expand Down
23 changes: 2 additions & 21 deletions test/e2e/node_reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func nodeReuse(ctx context.Context, inputGetter func() NodeReuseInput) {
m3MachineTemplateName := fmt.Sprintf("%s-controlplane", input.ClusterName)
updateNodeReuse(ctx, input.Namespace, true, m3MachineTemplateName, managementClusterClient)
newM3MachineTemplateName := fmt.Sprintf("%s-new-controlplane", input.ClusterName)
createNewM3MachineTemplate(ctx, input.Namespace, newM3MachineTemplateName, m3MachineTemplateName, managementClusterClient, imageURL, imageChecksum)
CreateNewM3MachineTemplate(ctx, input.Namespace, newM3MachineTemplateName, m3MachineTemplateName, managementClusterClient, imageURL, imageChecksum)

Byf("Update KCP to upgrade k8s version and binaries from %s to %s [node_reuse]", kubernetesVersion, upgradedK8sVersion)
kcpObj := framework.GetKubeadmControlPlaneByCluster(ctx, framework.GetKubeadmControlPlaneByClusterInput{
Expand Down Expand Up @@ -330,7 +330,7 @@ func nodeReuse(ctx context.Context, inputGetter func() NodeReuseInput) {
By("Set nodeReuse field to 'True' and create new Metal3MachineTemplate for MD with upgraded image to boot [node_reuse]")
updateNodeReuse(ctx, input.Namespace, true, m3MachineTemplateName, managementClusterClient)
newM3MachineTemplateName = fmt.Sprintf("%s-new-workers", input.ClusterName)
createNewM3MachineTemplate(ctx, input.Namespace, newM3MachineTemplateName, m3MachineTemplateName, managementClusterClient, imageURL, imageChecksum)
CreateNewM3MachineTemplate(ctx, input.Namespace, newM3MachineTemplateName, m3MachineTemplateName, managementClusterClient, imageURL, imageChecksum)

Byf("Update MD to upgrade k8s version and binaries from %s to %s", kubernetesVersion, upgradedK8sVersion)
// Note: We have only 4 nodes (3 control-plane and 1 worker) so we
Expand Down Expand Up @@ -536,22 +536,3 @@ func deleteTaint(taints []corev1.Taint, taintsToDelete []corev1.Taint) ([]corev1
}
return newTaints, deleted
}

func createNewM3MachineTemplate(ctx context.Context, namespace string, newM3MachineTemplateName string, m3MachineTemplateName string, clusterClient client.Client, imageURL string, imageChecksum string) {
checksumType := "sha256"
imageFormat := "raw"

m3MachineTemplate := infrav1.Metal3MachineTemplate{}
Expect(clusterClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: m3MachineTemplateName}, &m3MachineTemplate)).To(Succeed())

newM3MachineTemplate := m3MachineTemplate.DeepCopy()
cleanObjectMeta(&newM3MachineTemplate.ObjectMeta)

newM3MachineTemplate.Spec.Template.Spec.Image.URL = imageURL
newM3MachineTemplate.Spec.Template.Spec.Image.Checksum = imageChecksum
newM3MachineTemplate.Spec.Template.Spec.Image.DiskFormat = &imageFormat
newM3MachineTemplate.Spec.Template.Spec.Image.ChecksumType = &checksumType
newM3MachineTemplate.ObjectMeta.Name = newM3MachineTemplateName

Expect(clusterClient.Create(ctx, newM3MachineTemplate)).To(Succeed(), "Failed to create new Metal3MachineTemplate")
}
4 changes: 2 additions & 2 deletions test/e2e/upgrade_kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func upgradeKubernetes(ctx context.Context, inputGetter func() upgradeKubernetes
By("Create new KCP Metal3MachineTemplate with upgraded image to boot")
m3MachineTemplateName := fmt.Sprintf("%s-controlplane", clusterName)
newM3MachineTemplateName := fmt.Sprintf("%s-new-controlplane", clusterName)
createNewM3MachineTemplate(ctx, namespace, newM3MachineTemplateName, m3MachineTemplateName, clusterClient, imageURL, imageChecksum)
CreateNewM3MachineTemplate(ctx, namespace, newM3MachineTemplateName, m3MachineTemplateName, clusterClient, imageURL, imageChecksum)

Byf("Update KCP to upgrade k8s version and binaries from %s to %s", kubernetesVersion, upgradedK8sVersion)
kcpObj := framework.GetKubeadmControlPlaneByCluster(ctx, framework.GetKubeadmControlPlaneByClusterInput{
Expand Down Expand Up @@ -177,7 +177,7 @@ func upgradeKubernetes(ctx context.Context, inputGetter func() upgradeKubernetes
By("Create new Metal3MachineTemplate for MD with upgraded image to boot")
m3MachineTemplateName = fmt.Sprintf("%s-workers", clusterName)
newM3MachineTemplateName = fmt.Sprintf("%s-new-workers", clusterName)
createNewM3MachineTemplate(ctx, namespace, newM3MachineTemplateName, m3MachineTemplateName, clusterClient, imageURL, imageChecksum)
CreateNewM3MachineTemplate(ctx, namespace, newM3MachineTemplateName, m3MachineTemplateName, clusterClient, imageURL, imageChecksum)

Byf("Update MD to upgrade k8s version and binaries from %s to %s", kubernetesVersion, upgradedK8sVersion)
helper, err = patch.NewHelper(machineDeploy, clusterClient)
Expand Down

0 comments on commit 8d08228

Please sign in to comment.