Skip to content

Commit

Permalink
Merge pull request #346 from alknopfler/fix-ignition-rke2-install
Browse files Browse the repository at this point in the history
fix issue with rke2-install
  • Loading branch information
salasberryfin authored Jul 2, 2024
2 parents 45d668e + b3e4e9c commit 3b8655d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 29 deletions.
3 changes: 2 additions & 1 deletion bootstrap/internal/ignition/butane/butane.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ systemd:
Description=rke2-install
Wants=network-online.target
After=network-online.target network.target
ConditionPathExists=!/run/cluster-api/bootstrap-success.complete
ConditionPathExists=!/etc/cluster-api/bootstrap-success.complete
[Service]
User=root
# To not restart the unit when it exits, as it is expected.
Expand Down Expand Up @@ -105,6 +105,7 @@ storage:
{{- end }}
- path: /etc/rke2-install.sh
mode: 0700
overwrite: true
contents:
inline: |
#!/bin/bash
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/internal/ignition/butane/butane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = Describe("Render", func() {

Expect(ign.Systemd.Units).To(HaveLen(3))
Expect(ign.Systemd.Units[0].Name).To(Equal("rke2-install.service"))
Expect(ign.Systemd.Units[0].Contents).To(Equal(pointer.String("[Unit]\nDescription=rke2-install\nWants=network-online.target\nAfter=network-online.target network.target\nConditionPathExists=!/run/cluster-api/bootstrap-success.complete\n[Service]\nUser=root\n# To not restart the unit when it exits, as it is expected.\nType=oneshot\nExecStart=/etc/rke2-install.sh\n[Install]\nWantedBy=multi-user.target\n")))
Expect(ign.Systemd.Units[0].Contents).To(Equal(pointer.String("[Unit]\nDescription=rke2-install\nWants=network-online.target\nAfter=network-online.target network.target\nConditionPathExists=!/etc/cluster-api/bootstrap-success.complete\n[Service]\nUser=root\n# To not restart the unit when it exits, as it is expected.\nType=oneshot\nExecStart=/etc/rke2-install.sh\n[Install]\nWantedBy=multi-user.target\n")))
Expect(ign.Systemd.Units[0].Enabled).To(Equal(pointer.Bool(true)))

Expect(ign.Systemd.Units[1].Name).To(Equal("ntpd.service"))
Expand Down
6 changes: 4 additions & 2 deletions bootstrap/internal/ignition/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ var (
"--kubeconfig /etc/rancher/rke2/rke2.yaml |" +
" kubectl apply -f- --kubeconfig /etc/rancher/rke2/rke2.yaml",
"restorecon /etc/systemd/system/rke2-server.service",
"mkdir -p /run/cluster-api && echo success > /run/cluster-api/bootstrap-success.complete",
"mkdir -p /run/cluster-api /etc/cluster-api",
"echo success | tee /run/cluster-api/bootstrap-success.complete /etc/cluster-api/bootstrap-success.complete > /dev/null",
"setenforce 1",
}

Expand All @@ -52,7 +53,8 @@ var (
"systemctl enable rke2-agent.service",
"systemctl start rke2-agent.service",
"restorecon /etc/systemd/system/rke2-agent.service",
"mkdir -p /run/cluster-api && echo success > /run/cluster-api/bootstrap-success.complete",
"mkdir -p /run/cluster-api /etc/cluster-api",
"echo success | tee /run/cluster-api/bootstrap-success.complete /etc/cluster-api/bootstrap-success.complete > /dev/null",
"setenforce 1",
}
)
Expand Down
12 changes: 6 additions & 6 deletions bootstrap/internal/ignition/ignition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ var _ = Describe("getControlPlaneRKE2Commands", func() {
It("should return slice of control plane commands", func() {
commands, err := getControlPlaneRKE2Commands(baseUserData)
Expect(err).ToNot(HaveOccurred())
Expect(commands).To(HaveLen(9))
Expect(commands).To(HaveLen(10))
Expect(commands).To(ContainElements(fmt.Sprintf(controlPlaneCommand, baseUserData.RKE2Version), serverDeployCommands[0], serverDeployCommands[1]))
})

It("should return slice of control plane commands with air gapped", func() {
baseUserData.AirGapped = true
commands, err := getControlPlaneRKE2Commands(baseUserData)
Expect(err).ToNot(HaveOccurred())
Expect(commands).To(HaveLen(9))
Expect(commands).To(HaveLen(10))
Expect(commands).To(ContainElements(airGappedControlPlaneCommand, serverDeployCommands[0], serverDeployCommands[1]))
})

Expand All @@ -224,7 +224,7 @@ var _ = Describe("getControlPlaneRKE2Commands", func() {
baseUserData.AirGappedChecksum = "abcd"
commands, err := getControlPlaneRKE2Commands(baseUserData)
Expect(err).ToNot(HaveOccurred())
Expect(commands).To(HaveLen(10))
Expect(commands).To(HaveLen(11))
Expect(commands).To(ContainElements(fmt.Sprintf(airGappedChecksumCommand, "abcd"), airGappedControlPlaneCommand, serverDeployCommands[0], serverDeployCommands[1]))
})

Expand Down Expand Up @@ -256,15 +256,15 @@ var _ = Describe("getWorkerRKE2Commands", func() {
It("should return slice of worker commands", func() {
commands, err := getWorkerRKE2Commands(baseUserData)
Expect(err).ToNot(HaveOccurred())
Expect(commands).To(HaveLen(8))
Expect(commands).To(HaveLen(9))
Expect(commands).To(ContainElements(fmt.Sprintf(workerCommand, baseUserData.RKE2Version), workerDeployCommands[0], workerDeployCommands[1]))
})

It("should return slice of worker commands with air gapped", func() {
baseUserData.AirGapped = true
commands, err := getWorkerRKE2Commands(baseUserData)
Expect(err).ToNot(HaveOccurred())
Expect(commands).To(HaveLen(8))
Expect(commands).To(HaveLen(9))
Expect(commands).To(ContainElements(airGappedWorkerCommand, workerDeployCommands[0], workerDeployCommands[1]))
})

Expand All @@ -273,7 +273,7 @@ var _ = Describe("getWorkerRKE2Commands", func() {
baseUserData.AirGappedChecksum = "abcd"
commands, err := getWorkerRKE2Commands(baseUserData)
Expect(err).ToNot(HaveOccurred())
Expect(commands).To(HaveLen(9))
Expect(commands).To(HaveLen(10))
Expect(commands).To(ContainElements(fmt.Sprintf(airGappedChecksumCommand, "abcd"), workerDeployCommands[0], workerDeployCommands[1]))
})

Expand Down
19 changes: 11 additions & 8 deletions pkg/etcd/client_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import (
"k8s.io/client-go/rest"
)

var (
subject *ClientGenerator
)
var subject *ClientGenerator

func TestNewEtcdClientGenerator(t *testing.T) {
g := NewWithT(t)
Expand Down Expand Up @@ -128,7 +126,8 @@ func TestForLeader(t *testing.T) {
},
},
AlarmResponse: &clientv3.AlarmResponse{},
}}, nil
},
}, nil
},
expectedClient: Client{
Endpoint: "etcd-node-leader",
Expand All @@ -140,7 +139,8 @@ func TestForLeader(t *testing.T) {
},
},
AlarmResponse: &clientv3.AlarmResponse{},
}},
},
},
},
{
name: "Returns client for leader even when one or more nodes are down",
Expand All @@ -159,7 +159,8 @@ func TestForLeader(t *testing.T) {
},
},
AlarmResponse: &clientv3.AlarmResponse{},
}}, nil
},
}, nil
},
expectedClient: Client{
Endpoint: "etcd-node-leader",
Expand All @@ -170,7 +171,8 @@ func TestForLeader(t *testing.T) {
},
},
AlarmResponse: &clientv3.AlarmResponse{},
}},
},
},
},
{
name: "Fails when called with an empty node list",
Expand All @@ -193,7 +195,8 @@ func TestForLeader(t *testing.T) {
},
},
AlarmResponse: &clientv3.AlarmResponse{},
}}, nil
},
}, nil
},
expectedErr: "etcd leader is reported as 6c1 with name \"node-leader\", but we couldn't find a corresponding Node in the cluster",
},
Expand Down
4 changes: 1 addition & 3 deletions pkg/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

var (
ctx = ctrl.SetupSignalHandler()
)
var ctx = ctrl.SetupSignalHandler()

func TestEtcdMembers_WithErrors(t *testing.T) {
g := NewWithT(t)
Expand Down
13 changes: 8 additions & 5 deletions pkg/rke2/workload_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ var _ = Describe("Node metadata propagation", func() {
Name: "stub",
Namespace: ns.Name,
},
}}
},
}

machineDifferentNode = &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -101,7 +102,8 @@ var _ = Describe("Node metadata propagation", func() {
Name: "stub",
Namespace: ns.Name,
},
}}
},
}

machineNodeRefStatus = clusterv1.MachineStatus{
NodeRef: &corev1.ObjectReference{
Expand Down Expand Up @@ -365,7 +367,6 @@ var _ = Describe("Node metadata propagation", func() {
clusterv1.MachineAnnotation: machineDifferentNode.Name,
}))
})

})

var _ = Describe("Cloud-init fields validation", func() {
Expand Down Expand Up @@ -429,7 +430,8 @@ var _ = Describe("ClusterStatus validation", func() {
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
}},
}}
},
}

node2 = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -446,7 +448,8 @@ var _ = Describe("ClusterStatus validation", func() {
Type: corev1.NodeReady,
Status: corev1.ConditionFalse,
}},
}}
},
}

servingSecret = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down
1 change: 1 addition & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func dumpSpecResourcesAndCleanup(ctx context.Context, input cleanupInput) {
input.AdditionalCleanup()
}
}

func localLoadE2EConfig(configPath string) *clusterctl.E2EConfig {
configData, err := os.ReadFile(configPath) //nolint:gosec
Expect(err).ToNot(HaveOccurred(), "Failed to read the e2e test config file")
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func loadE2EConfig(configPath string) *clusterctl.E2EConfig {
// TODO: This is commented out as it assumes kubeadm and errors if its not there
// Remove localLoadE2EConfig and use the line below when this issue is resolved:
// https://github.com/kubernetes-sigs/cluster-api/issues/3983
//config := clusterctl.LoadE2EConfig(ctx, clusterctl.LoadE2EConfigInput{ConfigPath: configPath})
// config := clusterctl.LoadE2EConfig(ctx, clusterctl.LoadE2EConfigInput{ConfigPath: configPath})
config := localLoadE2EConfig(configPath)
Expect(config).ToNot(BeNil(), "Failed to load E2E config from %s", configPath)

Expand Down
1 change: 0 additions & 1 deletion test/e2e/e2e_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ var _ = Describe("Workload cluster creation", func() {
Getter: bootstrapClusterProxy.GetClient(),
ControlPlane: client.ObjectKeyFromObject(result.ControlPlane),
}, e2eConfig.GetIntervals(specName, "wait-control-plane")...)

})
})
})
1 change: 0 additions & 1 deletion test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ func WaitForClusterToUpgrade(ctx context.Context, input WaitForClusterToUpgradeI
totalMachineCount = *input.ControlPlane.Spec.Replicas
} else {
totalMachineCount = *input.LegacyControlPlane.Spec.Replicas

}
for _, md := range input.MachineDeployments {
totalMachineCount += *md.Spec.Replicas
Expand Down

0 comments on commit 3b8655d

Please sign in to comment.