Skip to content

Commit

Permalink
Implement ClusterctlConfig with controleler
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Sep 16, 2024
1 parent 722d744 commit 34980a3
Show file tree
Hide file tree
Showing 17 changed files with 711 additions and 38 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.vscode
bin/
test/
**/*.yaml
hack/
docs/
scripts/
Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/capiprovider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type CAPIProviderSpec struct {

// Type is the type of the provider to enable
// +required
// +kubebuilder:validation:Enum=infrastructure;core;controlPlane;bootstrap;addon;runtimeextension;ipam
// +kubebuilder:example=infrastructure
// +kubebuilder:example=InfrastructureProvider
Type Type `json:"type"`

// Credentials is the structure holding the credentials to use for the provider. Only one credential type could be set at a time.
Expand Down
97 changes: 97 additions & 0 deletions api/v1alpha1/clusterctl_config_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
Copyright © 2023 - 2024 SUSE LLC
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"
)

// ClusterctlConfigName is a name of the clusterctl config in any namespace.
const (
ClusterctlConfigName string = "clusterctl-config"
)

// ClusterctlConfigSpec defines the user overrides for images and known providers with sources
//
//nolint:lll
type ClusterctlConfigSpec struct {
// Images is a list of image overrided for specified providers
Images []Image `json:"images"`

// Provider overrides
Providers ProviderList `json:"providers"`
}

// Provider allows to define providers with known URLs to pull the components.
type Provider struct {
// Name of the provider
// +required
Name string `json:"name"`

// URL of the provider components. Will be used unless and override is specified
// +required
URL string `json:"url"`

// Type is the type of the provider
// +required
// +kubebuilder:validation:Enum=infrastructure;core;controlPlane;bootstrap;addon;runtimeextension;ipam
// +kubebuilder:example=infrastructure
ProviderType Type `json:"type"`
}

// ProviderList is a list of providers.
type ProviderList []Provider

// Image allows to define transformations to apply to the image contained in the YAML manifests.
type Image struct {
// Repository sets the container registry override to pull images from.
// +kubebuilder:example=my-registry/my-org
Repository string `json:"repository,omitempty"`

// Tag allows to specify a tag for the images.
Tag string `json:"tag,omitempty"`

// Name of the provider image override
// +required
// +kubebuilder:example=all
Name string `json:"name"`
}

// ClusterctlConfig is the Schema for the CAPI Clusterctl config API.
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:validation:XValidation:message="Clusterctl Config should be named clusterctl-config.",rule="self.metadata.name == 'clusterctl-config'"
type ClusterctlConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

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

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ClusterctlConfig{}, &ClusterctlConfigList{})
}
1 change: 1 addition & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
// AddKnownTypes adds the list of known types to api.Scheme.
func AddKnownTypes(scheme *runtime.Scheme) {
scheme.AddKnownTypes(GroupVersion, &CAPIProvider{}, &CAPIProviderList{})
scheme.AddKnownTypes(GroupVersion, &ClusterctlConfig{}, &ClusterctlConfigList{})

for _, provider := range Providers {
if provider, ok := provider.(runtime.Object); ok {
Expand Down
132 changes: 132 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.

111 changes: 111 additions & 0 deletions charts/rancher-turtles/templates/rancher-turtles-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,115 @@ spec:
subresources:
status: {}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
helm.sh/resource-policy: keep
name: clusterctlconfigs.turtles-capi.cattle.io
spec:
group: turtles-capi.cattle.io
names:
kind: ClusterctlConfig
listKind: ClusterctlConfigList
plural: clusterctlconfigs
singular: clusterctlconfig
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: ClusterctlConfig is the Schema for the CAPI Clusterctl config
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: ClusterctlConfigSpec defines the user overrides for images
and known providers with sources
properties:
images:
description: Images is a list of image overrided for specified providers
items:
description: Image allows to define transformations to apply to
the image contained in the YAML manifests.
properties:
name:
description: Name of the provider image override
example: all
type: string
repository:
description: Repository sets the container registry override
to pull images from.
example: my-registry/my-org
type: string
tag:
description: Tag allows to specify a tag for the images.
type: string
required:
- name
type: object
type: array
providers:
description: Provider overrides
items:
description: Provider allows to define providers with known URLs
to pull the components.
properties:
name:
description: Name of the provider
type: string
type:
description: Type is the type of the provider
enum:
- infrastructure
- core
- controlPlane
- bootstrap
- addon
- runtimeextension
- ipam
example: infrastructure
type: string
url:
description: URL of the provider components. Will be used unless
and override is specified
type: string
required:
- name
- type
- url
type: object
type: array
required:
- images
- providers
type: object
type: object
x-kubernetes-validations:
- message: Clusterctl Config should be named clusterctl-config.
rule: self.metadata.name == 'clusterctl-config'
served: true
storage: true
subresources:
status: {}
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down Expand Up @@ -3277,6 +3386,8 @@ rules:
resources:
- capiproviders
- capiproviders/status
- clusterctlconfigs
- clusterctlconfigs/status
verbs:
- get
- list
Expand Down
Loading

0 comments on commit 34980a3

Please sign in to comment.