Skip to content

Commit

Permalink
internal: move kube-vip embedding to internal to make it reusable in …
Browse files Browse the repository at this point in the history
…e2e test
  • Loading branch information
chrischdi committed Jun 21, 2024
1 parent 181add3 commit 503a5df
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package kubevip provides the files required to run kube-vip in a cluster.
package kubevip

import (
Expand All @@ -38,12 +39,13 @@ var (
kubeVipPodRaw string
)

func newKubeVIPFiles() []bootstrapv1.File {
// Files returns the files required for a control plane node to run kube-vip.
func Files() []bootstrapv1.File {
return []bootstrapv1.File{
{
Owner: "root:root",
Path: "/etc/kubernetes/manifests/kube-vip.yaml",
Content: kubeVIPPodYAML(),
Content: PodYAML(),
Permissions: "0644",
},
// This file is part of the workaround for https://github.com/kube-vip/kube-vip/issues/692
Expand All @@ -63,7 +65,8 @@ func newKubeVIPFiles() []bootstrapv1.File {
}
}

func kubeVIPPodYAML() string {
// PodYAML returns the static pod manifest required to run kube-vip.
func PodYAML() string {
pod := &corev1.Pod{}

if err := yaml.Unmarshal([]byte(kubeVipPodRaw), pod); err != nil {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions packaging/flavorgen/flavors/clusterclass_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newClusterClass() clusterv1.ClusterClass {
},
ControlPlane: getControlPlaneClass(),
Workers: getWorkersClass(),
Variables: getClusterClassVariables(false),
Variables: GetClusterClassVariables(false),
Patches: getClusterClassPatches(),
},
}
Expand All @@ -81,7 +81,7 @@ func newVMWareClusterClass() clusterv1.ClusterClass {
},
ControlPlane: getVMWareControlPlaneClass(),
Workers: getVMWareWorkersClass(),
Variables: getClusterClassVariables(true),
Variables: GetClusterClassVariables(true),
Patches: getVMWareClusterClassPatches(),
},
}
Expand Down Expand Up @@ -238,7 +238,7 @@ func getEnableSSHIntoNodesTemplate() *string {
return ptr.To(string(templateStr))
}

func getClusterClassVariables(supervisorMode bool) []clusterv1.ClusterClassVariable {
func GetClusterClassVariables(supervisorMode bool) []clusterv1.ClusterClassVariable {
variables := []clusterv1.ClusterClassVariable{
{
Name: "sshKey",
Expand Down
4 changes: 3 additions & 1 deletion packaging/flavorgen/flavors/kubevip/kubevip.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ package kubevip

import (
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"

"sigs.k8s.io/cluster-api-provider-vsphere/internal/kubevip"
)

// PatchControlPlane adds kube-vip to a KubeadmControlPlane object.
func PatchControlPlane(cp *controlplanev1.KubeadmControlPlane) {
cp.Spec.KubeadmConfigSpec.Files = append(cp.Spec.KubeadmConfigSpec.Files, newKubeVIPFiles()...)
cp.Spec.KubeadmConfigSpec.Files = append(cp.Spec.KubeadmConfigSpec.Files, kubevip.Files()...)
}
5 changes: 3 additions & 2 deletions packaging/flavorgen/flavors/kubevip/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ import (
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
"sigs.k8s.io/yaml"

"sigs.k8s.io/cluster-api-provider-vsphere/internal/kubevip"
"sigs.k8s.io/cluster-api-provider-vsphere/packaging/flavorgen/flavors/util"
)

// TopologyVariable returns the ClusterClass variable for kube-vip.
func TopologyVariable() (*clusterv1.ClusterVariable, error) {
out, err := json.Marshal(kubeVIPPodYAML())
out, err := json.Marshal(kubevip.PodYAML())
if err != nil {
return nil, errors.Wrapf(err, "failed to json-encode variable kubeVipPod")
}
Expand All @@ -52,7 +53,7 @@ func TopologyVariable() (*clusterv1.ClusterVariable, error) {
func TopologyPatch() clusterv1.ClusterClassPatch {
patches := []clusterv1.JSONPatch{}

for _, f := range newKubeVIPFiles() {
for _, f := range kubevip.Files() {
p := clusterv1.JSONPatch{
Op: "add",
Path: "/spec/template/spec/kubeadmConfigSpec/files/-",
Expand Down

0 comments on commit 503a5df

Please sign in to comment.