Skip to content

Commit

Permalink
✨ Add preparation of clusterclass (ionos-cloud#141)
Browse files Browse the repository at this point in the history
**What is the purpose of this pull request/Why do we need it?**

**Issue #, if available:**

**Description of changes:**

**Special notes for your reviewer:**

**Checklist:**
- [x] Documentation updated
- [ ] Unit Tests added
- [ ] E2E Tests added
- [x] Includes
[emojis](https://github.com/kubernetes-sigs/kubebuilder-release-tools?tab=readme-ov-file#kubebuilder-project-versioning)

---------

Signed-off-by: Jan Jansen <[email protected]>
  • Loading branch information
farodin91 authored and Mattes83 committed Jun 26, 2024
1 parent c909533 commit 7fae147
Show file tree
Hide file tree
Showing 9 changed files with 1,027 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ _artifacts/

# crs
templates/crs/cni/calico.yaml

#testing stuff
clusterctl-settings.json
templates/clusterclass-template-replaced.yaml
templates/cluster-template-topology-replaced.yaml
output/
54 changes: 54 additions & 0 deletions api/v1alpha1/ionoscloudclustertemplate_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
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"
)

// IonosCloudClusterTemplateSpec defines the desired state of IonosCloudClusterTemplate.
type IonosCloudClusterTemplateSpec struct {
Template IonosCloudClusterTemplateResource `json:"template"`
}

// IonosCloudClusterTemplateResource describes the data for creating a IonosCloudCluster from a template.
type IonosCloudClusterTemplateResource struct {
Spec IonosCloudClusterSpec `json:"spec"`
}

//+kubebuilder:object:root=true

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

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

//+kubebuilder:object:root=true

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

func init() {
objectTypes = append(objectTypes, &IonosCloudClusterTemplate{}, &IonosCloudClusterTemplateList{})
}
90 changes: 90 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: ionoscloudclustertemplates.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
names:
kind: IonosCloudClusterTemplate
listKind: IonosCloudClusterTemplateList
plural: ionoscloudclustertemplates
singular: ionoscloudclustertemplate
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: IonosCloudClusterTemplate is the Schema for the ionoscloudclustertemplates
API.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: IonosCloudClusterTemplateSpec defines the desired state of
IonosCloudClusterTemplate.
properties:
template:
description: IonosCloudClusterTemplateResource describes the data
for creating a IonosCloudCluster from a template.
properties:
spec:
description: IonosCloudClusterSpec defines the desired state of
IonosCloudCluster.
properties:
controlPlaneEndpoint:
description: |-
ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
TODO(gfariasalves): as of now, IP must be provided by the user as we still don't insert the
provider-provided block IP into the kube-vip manifest.
properties:
host:
description: The hostname on which the API server is serving.
type: string
port:
description: The port on which the API server is serving.
format: int32
type: integer
required:
- host
- port
type: object
x-kubernetes-validations:
- message: control plane endpoint host cannot be updated
rule: self.host == oldSelf.host || oldSelf.host == ''
- message: control plane endpoint port cannot be updated
rule: self.port == oldSelf.port || oldSelf.port == 0
credentialsRef:
description: CredentialsRef is a reference to the secret containing
the credentials to access the IONOS Cloud API.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
x-kubernetes-validations:
- message: credentialsRef.name must be provided
rule: has(self.name) && self.name != ''
location:
description: Location is the location where the data centers
should be located.
example: de/txl
minLength: 1
type: string
x-kubernetes-validations:
- message: location is immutable
rule: self == oldSelf
required:
- credentialsRef
- location
type: object
required:
- spec
type: object
required:
- template
type: object
type: object
served: true
storage: true
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# It should be run by config/default
resources:
- bases/infrastructure.cluster.x-k8s.io_ionoscloudclusters.yaml
- bases/infrastructure.cluster.x-k8s.io_ionoscloudclustertemplates.yaml
- bases/infrastructure.cluster.x-k8s.io_ionoscloudmachines.yaml
- bases/infrastructure.cluster.x-k8s.io_ionoscloudmachinetemplates.yaml
#+kubebuilder:scaffold:crdkustomizeresource
Expand Down
9 changes: 8 additions & 1 deletion envfile.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
export IONOS_TOKEN="token"
export IONOS_API_URL="https://api.ionos.com/cloudapi/v6"

# ClusterClass and Cluster API related environment variables
export NAMESPACE="default"

# Cluster API related environment variables
export CONTROL_PLANE_ENDPOINT_HOST="example.org"
export CONTROL_PLANE_ENDPOINT_IP="192.168.0.1"
export CONTROL_PLANE_ENDPOINT_PORT=6443
export CONTROL_PLANE_ENDPOINT_LOCATION="de/txl"
export CONTROL_PLANE_MACHINE_COUNT=3
export WORKER_MACHINE_COUNT=1
export CLUSTER_NAME="cluster-name"
export KUBERNETES_VERSION="1.29.2"

# Cluster related environment variables
export IONOSCLOUD_DATACENTER_ID="12345"
export IONOSCLOUD_MACHINE_NUM_CORES=2
export IONOSCLOUD_MACHINE_MEMORY_MB=4096
export IONOSCLOUD_MACHINE_IMAGE_ID=123456
export IONOSCLOUD_MACHINE_IMAGE_ID="123456"
export IONOSCLOUD_MACHINE_SSH_KEYS="ssh-ed25519 ..., ssh-ed25519 ..."

# ClusterClass related environment variables
export CLUSTER_CLASS_NAME="testclass"
39 changes: 39 additions & 0 deletions hack/test-cluster-class.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#/bin/bash

ROOT_DIR=$(cd $(realpath $(dirname $0))/.. && pwd)

if [[ ! -d "${ROOT_DIR}/output" ]]; then
echo "create output directory"
mkdir "${ROOT_DIR}/output"
fi

if [[ ! -f "${ROOT_DIR}/.envfile" ]]; then
echo "create .envfile from envfile.example"
exit 1
fi
source ${ROOT_DIR}/.envfile

echo "Setup Cluster API with ClusterResourceSet and ClusterTopology"
echo "export EXP_CLUSTER_RESOURCE_SET=\"true\""
echo "export CLUSTER_TOPOLOGY=\"true\""
echo "clusterctl init --infrastructure=ionoscloud-ionoscloud"

GENERATED_CLUSTER_CLASS_FILE="${ROOT_DIR}/output/generated-clusterclass-template.yaml"
GENERATED_CLUSTER_FILE="${ROOT_DIR}/output/generated-cluster-template-topology-calico.yaml"

clusterctl generate yaml --from "${ROOT_DIR}/templates/clusterclass-template.yaml" > $GENERATED_CLUSTER_CLASS_FILE
clusterctl generate cluster $CLUSTER_NAME -n $NAMESPACE --from "${ROOT_DIR}/templates/cluster-template-topology-calico.yaml" > $GENERATED_CLUSTER_FILE

echo "Validate generated resources"
clusterctl alpha topology plan -f $GENERATED_CLUSTER_CLASS_FILE -f $GENERATED_CLUSTER_FILE -o "${ROOT_DIR}/output/"

echo "Apply cluster class resources"
echo "kubectl apply -f $GENERATED_CLUSTER_CLASS_FILE"
echo "Apply cluster which uses the cluster class resources"
echo "kubectl apply -f $GENERATED_CLUSTER_FILE"

echo "Installing calico cni"
echo "make crs-calico"
echo "kubectl apply -f ${ROOT_DIR}/templates/crs/cni/calico.yaml"

echo "Done"
Loading

0 comments on commit 7fae147

Please sign in to comment.