Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Dec 21, 2023
1 parent 025aceb commit 615d774
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
9 changes: 5 additions & 4 deletions packaging/flavorgen/flavors/kubevip/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ var (
func newKubeVIPFiles() []bootstrapv1.File {
return []bootstrapv1.File{
{
Owner: "root:root",
Path: "/etc/kubernetes/manifests/kube-vip.yaml",
Content: kubeVIPPod(),
Owner: "root:root",
Path: "/etc/kubernetes/manifests/kube-vip.yaml",
Content: kubeVIPPod(),
Permissions: "0644",
},
// This two patches are part of the workaround for https://github.com/kube-vip/kube-vip/issues/692
{
Expand All @@ -54,7 +55,7 @@ func newKubeVIPFiles() []bootstrapv1.File {
},
{
Owner: "root:root",
Path: "/etc/kube-vip-prepare.sh",
Path: "/etc/kube-vip-cleanup.sh",
Permissions: "0700",
Content: kubeVipCleanup,
},
Expand Down
33 changes: 21 additions & 12 deletions packaging/flavorgen/flavors/kubevip/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package kubevip
import (
_ "embed"
"encoding/json"
"fmt"
"strings"

"github.com/pkg/errors"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -63,22 +65,28 @@ func TopologyPatch() clusterv1.ClusterClassPatch {
patches := []clusterv1.JSONPatch{}

for _, f := range newKubeVIPFiles() {
p := clusterv1.JSONPatch{
Op: "add",
Path: "/spec/template/spec/kubeadmConfigSpec/files/-",
ValueFrom: &clusterv1.JSONPatchValue{},
}

// Special handling to make this patch work
if f.Path == "/etc/kubernetes/manifests/kube-vip.yaml" {
f.Content = `{{ printf "%q" (regexReplaceAll "(name: address\n +value:).*" .kubeVipPodManifest (printf "$1 %s" .controlPlaneIpAddr)) }}`
lines := []string{
fmt.Sprintf("owner: %q", f.Owner),
fmt.Sprintf("path: %q", f.Owner),
`content: {{ printf "%q" (regexReplaceAll "(name: address\n +value:).*" .kubeVipPodManifest (printf "$1 %s" .controlPlaneIpAddr)) }}`,
fmt.Sprintf("permissions: %q", f.Permissions),
}
p.ValueFrom.Template = pointer.String(strings.Join(lines, "\n"))
patches = append(patches, p)
continue
}

tpl, _ := fileToTemplate(f)

patches = append(
patches,
clusterv1.JSONPatch{
Op: "add",
Path: "/spec/template/spec/kubeadmConfigSpec/files/-",
ValueFrom: &clusterv1.JSONPatchValue{
Template: pointer.String(tpl),
},
},
)
p.ValueFrom.Template = pointer.String(tpl)
patches = append(patches, p)
}

// This two patches are part of the workaround for https://github.com/kube-vip/kube-vip/issues/684
Expand Down Expand Up @@ -113,6 +121,7 @@ func TopologyPatch() clusterv1.ClusterClassPatch {
}

func fileToTemplate(f bootstrapv1.File) (string, error) {

out, err := yaml.Marshal(f)
if err != nil {
return "", errors.Wrapf(err, "unable to wrap file %q", f.Path)
Expand Down
4 changes: 2 additions & 2 deletions templates/cluster-template-ignition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ spec:
status: {}
owner: root:root
path: /etc/kubernetes/manifests/kube-vip.yaml
permissions: "0400"
permissions: "0644"
- content: 127.0.0.1 localhost kubernetes
owner: root:root
path: /etc/kube-vip.hosts
Expand Down Expand Up @@ -215,7 +215,7 @@ spec:
sed -i 's#path: /etc/kubernetes/super-admin.conf#path: /etc/kubernetes/admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml || true
owner: root:root
path: /etc/kube-vip-prepare.sh
path: /etc/kube-vip-cleanup.sh
permissions: "0700"
format: ignition
ignition:
Expand Down
3 changes: 2 additions & 1 deletion templates/cluster-template-node-ipam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ spec:
status: {}
owner: root:root
path: /etc/kubernetes/manifests/kube-vip.yaml
permissions: "0644"
- content: 127.0.0.1 localhost kubernetes
owner: root:root
path: /etc/kube-vip.hosts
Expand Down Expand Up @@ -251,7 +252,7 @@ spec:
sed -i 's#path: /etc/kubernetes/super-admin.conf#path: /etc/kubernetes/admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml || true
owner: root:root
path: /etc/kube-vip-prepare.sh
path: /etc/kube-vip-cleanup.sh
permissions: "0700"
initConfiguration:
nodeRegistration:
Expand Down
3 changes: 2 additions & 1 deletion templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ spec:
status: {}
owner: root:root
path: /etc/kubernetes/manifests/kube-vip.yaml
permissions: "0644"
- content: 127.0.0.1 localhost kubernetes
owner: root:root
path: /etc/kube-vip.hosts
Expand Down Expand Up @@ -241,7 +242,7 @@ spec:
sed -i 's#path: /etc/kubernetes/super-admin.conf#path: /etc/kubernetes/admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml || true
owner: root:root
path: /etc/kube-vip-prepare.sh
path: /etc/kube-vip-cleanup.sh
permissions: "0700"
initConfiguration:
nodeRegistration:
Expand Down
12 changes: 6 additions & 6 deletions templates/clusterclass-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ spec:
- op: add
path: /spec/template/spec/kubeadmConfigSpec/files/-
valueFrom:
template: |
content: '{{ printf "%q" (regexReplaceAll "(name: address\n +value:).*" .kubeVipPodManifest
(printf "$1 %s" .controlPlaneIpAddr)) }}'
owner: root:root
path: /etc/kubernetes/manifests/kube-vip.yaml
template: |-
owner: "root:root"
path: "root:root"
content: {{ printf "%q" (regexReplaceAll "(name: address\n +value:).*" .kubeVipPodManifest (printf "$1 %s" .controlPlaneIpAddr)) }}
permissions: "0644"
- op: add
path: /spec/template/spec/kubeadmConfigSpec/files/-
valueFrom:
Expand Down Expand Up @@ -219,7 +219,7 @@ spec:
sed -i 's#path: /etc/kubernetes/super-admin.conf#path: /etc/kubernetes/admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml || true
owner: root:root
path: /etc/kube-vip-prepare.sh
path: /etc/kube-vip-cleanup.sh
permissions: "0700"
- op: add
path: /spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-
Expand Down

0 comments on commit 615d774

Please sign in to comment.