Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jun 21, 2024
1 parent 3eb0cfa commit b00f7b3
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 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.
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
73 changes: 69 additions & 4 deletions test/infrastructure/test-extension/topologymutation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
Expand All @@ -39,8 +40,7 @@ import (

infrav1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1"
vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
"sigs.k8s.io/cluster-api-provider-vsphere/packaging/flavorgen/flavors"
"sigs.k8s.io/cluster-api-provider-vsphere/packaging/flavorgen/flavors/kubevip"
"sigs.k8s.io/cluster-api-provider-vsphere/internal/kubevip"
)

// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;patch;update;create
Expand Down Expand Up @@ -340,6 +340,71 @@ func (h *ExtensionHandlers) DiscoverVariables(ctx context.Context, _ *runtimehoo
log.Info("DiscoverVariables called")

resp.Status = runtimehooksv1.ResponseStatusSuccess
// Using false to get all variables. When patching supervisor templates we just won't use the additional variables.
resp.Variables = flavors.GetClusterClassVariables(false)

// The variables are a copy of what flavorgen generates in `packaging/flavorgen/flavors/clusterclass_generators.go`
resp.Variables = []clusterv1.ClusterClassVariable{
{
Name: "sshKey",
Required: false,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Public key to SSH onto the cluster nodes.",
Type: "string",
},
},
},
{
Name: "controlPlaneIpAddr",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Description: "Floating VIP for the control plane.",
},
},
},
{
Name: "controlPlanePort",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "integer",
Description: "Port for the control plane endpoint.",
},
},
},
{
Name: "kubeVipPodManifest",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Description: "kube-vip manifest for the control plane.",
},
},
},
{
Name: "infraServer",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"url": {Type: "string"},
"thumbprint": {Type: "string"},
},
},
},
},
{
Name: "credsSecretName",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Description: "Secret containing the credentials for the infra cluster.",
},
},
},
}
}

0 comments on commit b00f7b3

Please sign in to comment.