Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster class support #10

Merged
merged 21 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,21 @@ CALICO_VERSION ?= v3.26.3
crs-calico: ## Generates crs manifests for Calico.
curl -o templates/crs/cni/calico.yaml https://raw.githubusercontent.com/projectcalico/calico/$(CALICO_VERSION)/manifests/calico.yaml

METALLB_VERSION ?= 0.14.3
METALLB_VERSION ?= 0.14.4
FRR_K8S_DIR = metallb/charts/metallb/charts/frr-k8s/templates
METALLB_TOLERATIONS = [{"key": "node-role.kubernetes.io/load-balancer", "operator": "Exists", "effect": "NoSchedule"}]
LB_TOLERATIONS = [{"key": "node-role.kubernetes.io/load-balancer", "operator": "Exists", "effect": "NoSchedule"}]
CP_TOLERATIONS = [{"key": "node-role.kubernetes.io/control-plane", "operator": "Exists", "effect": "NoSchedule"}]
FRR_NODESELECTOR = {"node-role.kubernetes.io/load-balancer": ""}
.PHONY: crs-metallb
crs-metallb: ## Generates crs manifests for MetalLB.
$(HELM) repo add metallb https://metallb.github.io/metallb
$(HELM) template metallb metallb/metallb --version $(METALLB_VERSION) --set frrk8s.enabled=true,speaker.frr.enabled=false --set-json 'controller.tolerations=$(METALLB_TOLERATIONS)' --set-json 'speaker.tolerations=$(METALLB_TOLERATIONS)' --set-json 'frr-k8s.frrk8s.tolerations=$(METALLB_TOLERATIONS)' --namespace=metallb-system > templates/crs/metallb.yaml

@# fixup namespacing in frr-k8s to work with clusterresourcesets
@sed -e '7bp;48bp;69bp;1682bp;1854bp;1887bp;2253bp;bn' -e ':p i\ namespace: "metallb-system"' -e ':n' -i templates/crs/metallb.yaml
$(HELM) template metallb metallb/metallb --version $(METALLB_VERSION) \
--set frrk8s.enabled=true,speaker.frr.enabled=false \
--set-json 'controller.tolerations=$(CP_TOLERATIONS)' \
--set-json 'speaker.tolerations=$(LB_TOLERATIONS)' \
--set-json 'frr-k8s.frrk8s.tolerations=$(LB_TOLERATIONS)' \
--set-json 'frr-k8s.frrk8s.nodeSelector=$(FRR_NODESELECTOR)' \
--namespace=metallb-system > templates/crs/metallb.yaml


##@ Release
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/proxmoxcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ type ProxmoxClusterSpec struct {
// DNSServers contains information about nameservers used by the machines.
// +kubebuilder:validation:MinItems=1
DNSServers []string `json:"dnsServers"`

// NodeCloneSpec is the configuration pertaining to all items configurable
// in the configuration and cloning of a proxmox VM. Multiple types of nodes can be specified.
// +optional
CloneSpec *ProxmoxClusterCloneSpec `json:"cloneSpec,omitempty"`
}

// ProxmoxClusterCloneSpec is the configuration pertaining to all items configurable
// in the configuration and cloning of a proxmox VM.
type ProxmoxClusterCloneSpec struct {
// +kubebuilder:validation:XValidation:rule="has(self.controlPlane)",message="Cowardly refusing to deploy cluster without control plane"
ProxmoxMachineSpec map[string]ProxmoxMachineSpec `json:"machineSpec"`

// SshAuthorizedKeys contains the authorized keys deployed to the PROXMOX VMs.
// +optional
SSHAuthorizedKeys []string `json:"sshAuthorizedKeys,omitempty"`

// VirtualIPNetworkInterface is the interface the k8s control plane binds to.
// +optional
VirtualIPNetworkInterface string `json:"virtualIPNetworkInterface,omitempty"`
}

// IPConfigSpec contains information about available IP config.
Expand Down
20 changes: 19 additions & 1 deletion api/v1alpha1/proxmoxcluster_types_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 IONOS Cloud.
Copyright 2023-2024 IONOS Cloud.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -85,6 +85,15 @@ func defaultCluster() *ProxmoxCluster {
Prefix: 24,
},
DNSServers: []string{"1.2.3.4"},
CloneSpec: &ProxmoxClusterCloneSpec{
ProxmoxMachineSpec: map[string]ProxmoxMachineSpec{
"controlPlane": {
VirtualMachineCloneSpec: VirtualMachineCloneSpec{
SourceNode: "pve1",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -129,6 +138,15 @@ var _ = Describe("ProxmoxCluster Test", func() {
Expect(k8sClient.Create(context.Background(), defaultCluster())).To(Succeed())
})

Context("CloneSpecs", func() {
It("Should not allow Cluster without ControlPlane nodes", func() {
dc := defaultCluster()
dc.Spec.CloneSpec.ProxmoxMachineSpec = map[string]ProxmoxMachineSpec{}

Expect(k8sClient.Create(context.Background(), dc)).Should(MatchError(ContainSubstring("control plane")))
})
})

Context("IPV6Config", func() {
It("Should not allow empty addresses", func() {
dc := defaultCluster()
Expand Down
60 changes: 60 additions & 0 deletions api/v1alpha1/proxmoxclustertemplate_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2024 IONOS Cloud.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// ProxmoxClusterTemplateSpec defines the desired state of ProxmoxClusterTemplate.
type ProxmoxClusterTemplateSpec struct {
Template ProxmoxClusterTemplateResource `json:"template"`
}

// ProxmoxClusterTemplateResource defines the spec and metadata for ProxmoxClusterTemplate supported by capi.
type ProxmoxClusterTemplateResource struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
Spec ProxmoxClusterSpec `json:"spec"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ProxmoxClusterTemplate is the Schema for the proxmoxclustertemplates API.
type ProxmoxClusterTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ProxmoxClusterTemplateSpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true

// ProxmoxClusterTemplateList contains a list of ProxmoxClusterTemplate.
type ProxmoxClusterTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ProxmoxClusterTemplate `json:"items"`
}

func init() {
objectTypes = append(objectTypes, &ProxmoxClusterTemplate{}, &ProxmoxClusterTemplateList{})
}
123 changes: 123 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading