Skip to content

Commit

Permalink
test: add clusterclass scenario to e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Salas <[email protected]>
  • Loading branch information
salasberryfin committed Sep 3, 2024
1 parent 4aca5c7 commit cd6644b
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 28 deletions.
33 changes: 32 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ linters-settings:
local-prefixes: github.com/rancher/cluster-api-provider-rke2
gci:
custom-order: true
#local-prefixes: github.com/rancher/cluster-api-provider-rke2
sections:
- "standard"
- "blank"
Expand All @@ -68,6 +67,38 @@ linters-settings:
- "prefix(github.com/rancher/cluster-api-provider-rke2)"
wsl:
force-err-cuddling: false
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
#
# Rules in addition to the recommended configuration above.
#
- name: bool-literal-in-expr
- name: constant-logical-expr
linters:
enable-all: true
disable:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/coreos/butane v0.19.0
github.com/coreos/ignition/v2 v2.18.0
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
github.com/go-logr/logr v1.4.2
github.com/google/gofuzz v1.2.0
github.com/onsi/ginkgo/v2 v2.20.1
Expand Down Expand Up @@ -56,7 +57,6 @@ require (
github.com/docker/docker v25.0.6+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
KubernetesVersionUpgradeTo = "KUBERNETES_VERSION_UPGRADE_TO"
CPMachineTemplateUpgradeTo = "CONTROL_PLANE_MACHINE_TEMPLATE_UPGRADE_TO"
WorkersMachineTemplateUpgradeTo = "WORKERS_MACHINE_TEMPLATE_UPGRADE_TO"
ControlPlaneMachineCount = "CONTROL_PLANE_MACHINE_COUNT"
WorkerMachineCount = "WORKER_MACHINE_COUNT"
IPFamily = "IP_FAMILY"
KindImageVersion = "KIND_IMAGE_VERSION"
)
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/config/e2e_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ variables:
KUBERNETES_VERSION: "v1.28.1"
KIND_IMAGE_VERSION: "v1.28.0"
NODE_DRAIN_TIMEOUT: "60s"
CONFORMANCE_WORKER_MACHINE_COUNT: "2"
CONFORMANCE_CONTROL_PLANE_MACHINE_COUNT: "1"
WORKER_MACHINE_COUNT: "2"
CONTROL_PLANE_MACHINE_COUNT: "1"
KUBERNETES_VERSION_UPGRADE_TO: "v1.28.12"
KUBERNETES_UPGRADE_OCI_IMAGE_ID: "${KUBERNETES_UPGRADE_OCI_IMAGE_ID}"
IP_FAMILY: "IPv4"
EXP_CLUSTER_RESOURCE_SET: "true"
EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION: "true"
EXP_MACHINE_POOL: "true"
CLUSTER_TOPOLOGY: "true"

intervals:
default/wait-controllers: ["3m", "10s"]
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build e2e
// +build e2e

/*
Copyright 2024 SUSE.
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 e2e

import (
_ "embed"
)

var (
//go:embed data/infrastructure/clusterclass-template-docker.yaml
ClusterClassDocker []byte
//go:embed data/infrastructure/cluster-from-clusterclass-template-docker.yaml
ClusterFromClusterClassDocker []byte
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: "${CLUSTER_NAME}"
namespace: "${NAMESPACE}"
spec:
clusterNetwork:
pods:
cidrBlocks:
- 10.45.0.0/16
serviceDomain: cluster.local
services:
cidrBlocks:
- 10.46.0.0/16
topology:
class: "${CLASS_NAME}"
version: ${KUBERNETES_VERSION}+rke2r1
controlPlane:
metadata: {}
replicas: ${CABPR_CP_REPLICAS}
workers:
machineDeployments:
- class: default-worker
name: md-0
replicas: ${CABPR_WK_REPLICAS}
variables:
- name: dockerKindImage
value: kindest/node:${KIND_IMAGE_VERSION}
205 changes: 205 additions & 0 deletions test/e2e/data/infrastructure/clusterclass-template-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: ClusterClass
metadata:
name: "${CLASS_NAME}"
namespace: "${NAMESPACE}"
spec:
controlPlane:
ref:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: RKE2ControlPlaneTemplate
name: ${CLASS_NAME}-control-plane
machineInfrastructure:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
name: ${CLASS_NAME}-control-plane
infrastructure:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerClusterTemplate
name: ${CLASS_NAME}-cluster
workers:
machineDeployments:
- class: default-worker
template:
bootstrap:
ref:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: RKE2ConfigTemplate
name: ${CLASS_NAME}-default-worker-bootstraptemplate
infrastructure:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
name: ${CLASS_NAME}-default-worker-machinetemplate
variables:
- name: dockerKindImage
required: true
schema:
openAPIV3Schema:
type: string
default: kindest/node:v1.28.12
patches:
- name: controlPlaneDockerKindImage
definitions:
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
matchResources:
controlPlane: true
jsonPatches:
- op: add
path: /spec/template/spec/customImage
valueFrom:
variable: dockerKindImage
- name: workerDockerKindImage
definitions:
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
matchResources:
machineDeploymentClass:
names:
- default-worker
jsonPatches:
- op: add
path: "/spec/template/spec/customImage"
valueFrom:
variable: dockerKindImage
---
apiVersion: v1
data:
value: |-
# generated by kind
global
log /dev/log local0
log /dev/log local1 notice
daemon
# limit memory usage to approximately 18 MB
# (see https://github.com/kubernetes-sigs/kind/pull/3115)
maxconn 100000
resolvers docker
nameserver dns 127.0.0.11:53
defaults
log global
mode tcp
option dontlognull
# TODO: tune these
timeout connect 5000
timeout client 50000
timeout server 50000
# allow to boot despite dns don't resolve backends
default-server init-addr none
frontend stats
bind *:8404
stats enable
stats uri /
stats refresh 10s
frontend control-plane
bind *:{{ .FrontendControlPlanePort }}
{{ if .IPv6 -}}
bind :::{{ .FrontendControlPlanePort }};
{{- end }}
default_backend kube-apiservers
backend kube-apiservers
option httpchk GET /healthz
http-check expect status 401
# TODO: we should be verifying (!)
{{range $server, $address := .BackendServers}}
server {{ $server }} {{ JoinHostPort $address $.BackendControlPlanePort }} check check-ssl verify none resolvers docker resolve-prefer {{ if $.IPv6 -}} ipv6 {{- else -}} ipv4 {{- end }}
{{- end}}
frontend rke2-join
bind *:9345
{{ if .IPv6 -}}
bind :::9345;
{{- end }}
default_backend rke2-servers
backend rke2-servers
option httpchk GET /v1-rke2/readyz
http-check expect status 403
{{range $server, $address := .BackendServers}}
server {{ $server }} {{ $address }}:9345 check check-ssl verify none
{{- end}}
kind: ConfigMap
metadata:
name: ${CLASS_NAME}-lb-config
namespace: "${NAMESPACE}"
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerClusterTemplate
metadata:
name: ${CLASS_NAME}-cluster
namespace: "${NAMESPACE}"
spec:
template:
spec:
loadBalancer:
customHAProxyConfigTemplateRef:
name: ${CLASS_NAME}-lb-config
---
kind: RKE2ControlPlaneTemplate
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
metadata:
name: ${CLASS_NAME}-control-plane
namespace: "${NAMESPACE}"
spec:
template:
spec:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
name: ${CLASS_NAME}-control-plane
serverConfig:
cni: calico
disableComponents:
kubernetesComponents: [ "cloudController"]
nodeDrainTimeout: 2m
rolloutStrategy:
type: "RollingUpdate"
rollingUpdate:
maxSurge: 1
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
metadata:
name: ${CLASS_NAME}-control-plane
namespace: "${NAMESPACE}"
spec:
template:
spec:
customImage: kindest/node:v1.28.0 # will be replaced by the patch
extraMounts:
- containerPath: "/var/run/docker.sock"
hostPath: "/var/run/docker.sock"
bootstrapTimeout: 15m
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
metadata:
name: ${CLASS_NAME}-default-worker-machinetemplate
namespace: "${NAMESPACE}"
spec:
template:
spec:
customImage: kindest/node:v1.28.0 # will be replaced by the patch
extraMounts:
- containerPath: "/var/run/docker.sock"
hostPath: "/var/run/docker.sock"
bootstrapTimeout: 15m
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: RKE2ConfigTemplate
metadata:
name: ${CLASS_NAME}-default-worker-bootstraptemplate
namespace: "${NAMESPACE}"
spec:
template:
spec: {}
Loading

0 comments on commit cd6644b

Please sign in to comment.