Skip to content

feat: Add ClusterResourceSet strategy for CNI installation #288

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

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
139 changes: 139 additions & 0 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright 2024 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
)

type Addons struct {
// +optional
CNI *CNI `json:"cni,omitempty"`

// +optional
NFD *NFD `json:"nfd,omitempty"`

// +optional
CPI *CPI `json:"cpi,omitempty"`

// +optional
CSIProviders *CSIProviders `json:"csi,omitempty"`
}

func (Addons) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Cluster configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
"csi": CSIProviders{}.VariableSchema().OpenAPIV3Schema,
"cpi": CPI{}.VariableSchema().OpenAPIV3Schema,
},
},
}
}

type AddonStrategy string

const (
AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
)

// CNI required for providing CNI configuration.
type CNI struct {
// +optional
Provider string `json:"provider,omitempty"`
// +optional
Strategy AddonStrategy `json:"strategy,omitempty"`
}

func (CNI) VariableSchema() clusterv1.VariableSchema {
supportedCNIProviders := []string{CNIProviderCalico}

return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"provider": {
Description: "CNI provider to deploy",
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedCNIProviders...),
},
"strategy": {
Description: "Addon strategy used to deploy the CNI provider to the workload cluster",
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(
AddonStrategyClusterResourceSet,
),
},
},
Required: []string{"provider", "strategy"},
},
}
}

// NFD tells us to enable or disable the node feature discovery addon.
type NFD struct{}

func (NFD) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
},
}
}

type CSIProviders struct {
// +optional
Providers []CSIProvider `json:"providers,omitempty"`
// +optional
DefaultClassName string `json:"defaultClassName,omitempty"`
}

type CSIProvider struct {
Name string `json:"name,omitempty"`
}

func (CSIProviders) VariableSchema() clusterv1.VariableSchema {
supportedCSIProviders := []string{CSIProviderAWSEBS}
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"providers": {
Type: "array",
Items: &clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(
supportedCSIProviders...),
},
},
},
},
"defaultClassName": {
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedCSIProviders...),
},
},
},
}
}

// CPI tells us to enable or disable the cloud provider interface.
type CPI struct{}

func (CPI) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
},
}
}
114 changes: 0 additions & 114 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
)

Expand Down Expand Up @@ -316,119 +315,6 @@ func (ImageRegistryCredentialsResource) VariableSchema() clusterv1.VariableSchem
}
}

type Addons struct {
// +optional
CNI *CNI `json:"cni,omitempty"`

// +optional
NFD *NFD `json:"nfd,omitempty"`

// +optional
CPI *CPI `json:"cpi,omitempty"`

// +optional
CSIProviders *CSIProviders `json:"csi,omitempty"`
}

func (Addons) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Cluster configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
"csi": CSIProviders{}.VariableSchema().OpenAPIV3Schema,
"cpi": CPI{}.VariableSchema().OpenAPIV3Schema,
},
},
}
}

// CNI required for providing CNI configuration.
type CNI struct {
Provider string `json:"provider,omitempty"`
}

func (CNI) VariableSchema() clusterv1.VariableSchema {
supportedCNIProviders := []string{CNIProviderCalico}

return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"provider": {
Description: "CNI provider to deploy",
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedCNIProviders...),
},
},
Required: []string{"provider"},
},
}
}

// NFD tells us to enable or disable the node feature discovery addon.
type NFD struct{}

func (NFD) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
},
}
}

type CSIProviders struct {
// +optional
Providers []CSIProvider `json:"providers,omitempty"`
// +optional
DefaultClassName string `json:"defaultClassName,omitempty"`
}

type CSIProvider struct {
Name string `json:"name,omitempty"`
}

func (CSIProviders) VariableSchema() clusterv1.VariableSchema {
supportedCSIProviders := []string{CSIProviderAWSEBS}
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"providers": {
Type: "array",
Items: &clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(
supportedCSIProviders...),
},
},
},
},
"defaultClassName": {
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedCSIProviders...),
},
},
},
}
}

// CPI tells us to enable or disable the cloud provider interface.
type CPI struct{}

func (CPI) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
},
}
}

func init() {
SchemeBuilder.Register(&ClusterConfig{})
}
14 changes: 7 additions & 7 deletions charts/capi-runtime-extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ A Helm chart for capi-runtime-extensions
| deployDefaultClusterClasses | bool | `true` | |
| deployment.replicas | int | `1` | |
| env | object | `{}` | |
| hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.content | string | `""` | |
| hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.name | string | `"calico-cni-installation-awscluster"` | |
| hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.create | bool | `true` | |
| hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content | string | `""` | |
| hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.name | string | `"calico-cni-installation-dockercluster"` | |
| hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.create | bool | `true` | |
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.content | string | `""` | |
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.name | string | `"calico-cni-installation-awscluster"` | |
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.create | bool | `true` | |
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.content | string | `""` | |
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.name | string | `"calico-cni-installation-dockercluster"` | |
| hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.create | bool | `true` | |
| hooks.CalicoCNI.crsStrategy.defaultTigeraOperatorConfigMap.name | string | `"tigera-operator"` | |
| hooks.CalicoCNI.defaultPodSubnet | string | `"192.168.0.0/16"` | |
| hooks.CalicoCNI.defaultTigeraOperatorConfigMap.name | string | `"tigera-operator"` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"ghcr.io/d2iq-labs/capi-runtime-extensions"` | |
| image.tag | string | `""` | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright 2023 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.create }}
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.name }}'
name: '{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.name }}'
data:
calico-installation: |
{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.content -}}
{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.AWSCluster.configMap.content | nindent 4}}
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.content -}}
{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.AWSCluster.configMap.content | nindent 4 }}
{{- else -}}
# This section includes base Calico installation configuration.
# For more information, see: https://docs.projectcalico.org/reference/installation/api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright 2023 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.create }}
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.name }}'
name: '{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.name }}'
data:
calico-installation: |
{{- if .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content -}}
{{ .Values.hooks.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content | nindent 4}}
{{- if .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.content -}}
{{ .Values.hooks.CalicoCNI.crsStrategy.defaultInstallationConfigMaps.DockerCluster.configMap.content | nindent 4 }}
{{- else -}}
# This section includes base Calico installation configuration.
# For more information, see: https://docs.projectcalico.org/reference/installation/api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data:
kind: ConfigMap
metadata:
creationTimestamp: null
name: '{{ .Values.hooks.CalicoCNI.defaultTigeraOperatorConfigMap.name }}'
name: '{{ .Values.hooks.CalicoCNI.crsStrategy.defaultTigeraOperatorConfigMap.name
}}'
2 changes: 1 addition & 1 deletion charts/capi-runtime-extensions/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
args:
- --webhook-cert-dir=/runtimehooks-certs/
- --calicocni.defaultsNamespace={{ .Release.Namespace }}
- --calicocni.crs.defaultsNamespace={{ .Release.Namespace }}
- --nfd.defaultsNamespace={{ .Release.Namespace }}
{{- range $key, $value := .Values.extraArgs }}
- --{{ $key }}={{ $value }}
Expand Down
27 changes: 14 additions & 13 deletions charts/capi-runtime-extensions/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
hooks:
CalicoCNI:
defaultPodSubnet: 192.168.0.0/16
defaultTigeraOperatorConfigMap:
name: tigera-operator
defaultInstallationConfigMaps:
DockerCluster:
create: true
configMap:
name: calico-cni-installation-dockercluster
content: ""
AWSCluster:
create: true
configMap:
name: calico-cni-installation-awscluster
content: ""
crsStrategy:
defaultTigeraOperatorConfigMap:
name: tigera-operator
defaultInstallationConfigMaps:
DockerCluster:
create: true
configMap:
name: calico-cni-installation-dockercluster
content: ""
AWSCluster:
create: true
configMap:
name: calico-cni-installation-awscluster
content: ""

deployDefaultClusterClasses: true

Expand Down
1 change: 1 addition & 0 deletions examples/capi-quick-start/aws-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
addons:
cni:
provider: calico
strategy: ClusterResourceSet
cpi: {}
csi:
providers:
Expand Down
1 change: 1 addition & 0 deletions examples/capi-quick-start/docker-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ spec:
addons:
cni:
provider: calico
strategy: ClusterResourceSet
nfd: {}
docker: {}
version: v1.27.5
Expand Down
Loading