Skip to content

Commit

Permalink
Merge pull request #742 from Danil-Grigorev/clusterctl-config-controller
Browse files Browse the repository at this point in the history
Implement ClusterctlConfig with controller
  • Loading branch information
alexander-demicev authored Sep 19, 2024
2 parents 41bdb50 + 0a89d81 commit 0070e17
Show file tree
Hide file tree
Showing 18 changed files with 713 additions and 56 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.

Loading

0 comments on commit 0070e17

Please sign in to comment.