diff --git a/Dockerfile b/Dockerfile index 342dce9..4a7db07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details FROM gcr.io/distroless/static:nonroot AS manager +LABEL source_repository="https://github.com/ironcore-dev/cluster-api-provider-metal" WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532 diff --git a/internal/controller/metalmachine_controller.go b/internal/controller/metalmachine_controller.go index 452556a..ce0471f 100644 --- a/internal/controller/metalmachine_controller.go +++ b/internal/controller/metalmachine_controller.go @@ -6,6 +6,7 @@ package controller import ( "context" "fmt" + "strings" "github.com/go-logr/logr" "github.com/ironcore-dev/cluster-api-provider-metal/internal/scope" @@ -220,7 +221,7 @@ func (r *MetalMachineReconciler) reconcileNormal(ctx context.Context, machineSco } machineScope.Info("Creating IgnitionSecret", "Secret", machineScope.MetalMachine.Name) - ignitionSecret, err := r.applyIgnitionSecret(ctx, machineScope.Logger, bootstrapSecret) + ignitionSecret, err := r.applyIgnitionSecret(ctx, machineScope.Logger, machineScope.MetalMachine, bootstrapSecret) if err != nil { machineScope.Error(err, "failed to create or patch ignition secret") return ctrl.Result{}, err @@ -253,7 +254,10 @@ func (r *MetalMachineReconciler) reconcileNormal(ctx context.Context, machineSco return reconcile.Result{}, nil } -func (r *MetalMachineReconciler) applyIgnitionSecret(ctx context.Context, log *logr.Logger, capidatasecret *corev1.Secret) (*corev1.Secret, error) { +func (r *MetalMachineReconciler) applyIgnitionSecret(ctx context.Context, log *logr.Logger, metalmachine *infrav1alpha1.MetalMachine, capidatasecret *corev1.Secret) (*corev1.Secret, error) { + dataSecret := capidatasecret + findAndReplaceIgnition(metalmachine, dataSecret) + secretObj := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("ignition-%s", capidatasecret.Name), @@ -264,8 +268,7 @@ func (r *MetalMachineReconciler) applyIgnitionSecret(ctx context.Context, log *l APIVersion: corev1.SchemeGroupVersion.String(), }, Data: map[string][]byte{ - // TODO: Make Metal Specific changes in the Ignition if necessary - DefaultIgnitionSecretKeyName: capidatasecret.Data["value"], + DefaultIgnitionSecretKeyName: dataSecret.Data["value"], }, } @@ -341,3 +344,13 @@ func (r *MetalMachineReconciler) ensureServerClaimBound(ctx context.Context, ser } return true, nil } + +func findAndReplaceIgnition(metalmachine *infrav1alpha1.MetalMachine, capidatasecret *corev1.Secret) { + data := capidatasecret.Data["value"] + + // replace $${METAL_HOSTNAME} with machine name + hostname := "%24%24%7BMETAL_HOSTNAME%7D" + modifiedData := strings.ReplaceAll(string(data), hostname, metalmachine.Name) + + capidatasecret.Data["value"] = []byte(modifiedData) +} diff --git a/templates/test/cluster_v1beta1_cluster.yaml b/templates/test/cluster_v1beta1_cluster.yaml index d640d83..185aa18 100644 --- a/templates/test/cluster_v1beta1_cluster.yaml +++ b/templates/test/cluster_v1beta1_cluster.yaml @@ -4,10 +4,10 @@ metadata: name: cluster-sample spec: controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1alpha1 + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlane name: kubeadmcontrolplane-sample-cp infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: MetalCluster name: metalcluster-sample diff --git a/templates/test/cluster_v1beta1_kubeadmcontrolplane.yaml b/templates/test/cluster_v1beta1_kubeadmcontrolplane.yaml index a2e8f28..084e0c0 100644 --- a/templates/test/cluster_v1beta1_kubeadmcontrolplane.yaml +++ b/templates/test/cluster_v1beta1_kubeadmcontrolplane.yaml @@ -40,6 +40,5 @@ spec: [TEST] test=1 preKubeadmCommands: - - envsubst < /etc/kubeadm.yml > /etc/kubeadm.yml.tmp - - mv /etc/kubeadm.yml.tmp /etc/kubeadm.yml + - hostnamectl set-hostname $${METAL_HOSTNAME} version: 1.29.4