-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from richardcase/providers_api
feat: add api for capi provider
- Loading branch information
Showing
19 changed files
with
3,987 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
Copyright SUSE 2023. | ||
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" | ||
|
||
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" | ||
) | ||
|
||
const ( | ||
// ProviderFinalizer is the finalizer apply on the CAPI Provider resource. | ||
ProviderFinalizer = "capiprovider.turtles.cattle.io" | ||
) | ||
|
||
// CAPIProviderSpec defines the desired state of CAPIProvider. | ||
// +kubebuilder:validation:XValidation:message="CAPI Provider version should be in the semver format",rule="!has(self.version) || self.version.matches(r\"\"\"^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$\"\"\")" | ||
// | ||
//nolint:lll | ||
type CAPIProviderSpec struct { | ||
// Name is the name of the provider to enable | ||
// +required | ||
// +kubebuilder:validation:Enum=aws;azure;gcp;docker;rke2 | ||
// +kubebuilder:example=aws | ||
Name ProviderName `json:"name"` | ||
|
||
// Type is the type of the provider to enable | ||
// +required | ||
// +kubebuilder:validation:Enum=infrastructure;core;controlPlane;bootstrap;addon | ||
// +kubebuilder:example=infrastructure | ||
Type ProviderType `json:"type"` | ||
|
||
// Credentials is the structure holding the credentials to use for the provider. Only one credential type could be set at a time. | ||
// +kubebuilder:example={rancherCloudCredential: user-credential} | ||
// +optional | ||
Credentials *ProviderCredentials `json:"credentials,omitempty"` | ||
|
||
// Features is a collection of features to enable. | ||
// +optional | ||
// +kubebuilder:example={machinePool: true, clusterResourceSet: true, clusterTopology: true} | ||
Features *Features `json:"features,omitempty"` | ||
|
||
// Variables is a map of environment variables to add to the content of the ConfigSecret | ||
// +optional | ||
// +kubebuilder:example={CLUSTER_TOPOLOGY:"true",EXP_CLUSTER_RESOURCE_SET:"true",EXP_MACHINE_POOL: "true"} | ||
Variables map[string]string `json:"variables"` | ||
|
||
// ProviderSpec is the spec of the underlying CAPI Provider resource. | ||
ProviderSpec *operatorv1.ProviderSpec `json:",inline"` | ||
} | ||
|
||
// Features defines a collection of features for the CAPI Provider to apply. | ||
type Features struct { | ||
// MachinePool if set to true will enable the machine pool feature. | ||
MachinePool bool `json:"machinePool,omitempty"` | ||
|
||
// ClusterResourceSet if set to true will enable the cluster resource set feature. | ||
ClusterResourceSet bool `json:"clusterResourceSet,omitempty"` | ||
|
||
// ClusterTopology if set to true will enable the clusterclass feature. | ||
ClusterTopology bool `json:"clusterTopology,omitempty"` | ||
} | ||
|
||
// ProviderCredentials defines the external credentials information for the provider. | ||
// +kubebuilder:validation:MaxProperties=1 | ||
// +kubebuilder:validation:MinProperties=1 | ||
// +structType=atomic | ||
// | ||
//nolint:godot | ||
type ProviderCredentials struct { | ||
// RancherCloudCredential is the Rancher Cloud Credential name | ||
RancherCloudCredential string `json:"rancherCloudCredential,omitempty"` | ||
|
||
// +optional | ||
// TODO: decide how to handle workload identity | ||
// WorkloadIdentityRef *WorkloadIdentityRef `json:"workloadIdentityRef,omitempty"` | ||
} | ||
|
||
// WorkloadIdentityRef is a reference to an identity to be used when reconciling the cluster. | ||
type WorkloadIdentityRef struct { | ||
// Name of the identity | ||
// +kubebuilder:validation:MinLength=1 | ||
Name string `json:"name"` | ||
|
||
// Kind of the identity | ||
Kind string `json:"kind"` | ||
} | ||
|
||
// CAPIProviderStatus defines the observed state of CAPIProvider. | ||
type CAPIProviderStatus struct { | ||
// Indicates the provider status | ||
// +kubebuilder:default=Pending | ||
State ProviderState `json:"state,omitempty"` | ||
|
||
// Variables is a map of environment variables added to the content of the ConfigSecret | ||
// +kubebuilder:default={CLUSTER_TOPOLOGY:"true",EXP_CLUSTER_RESOURCE_SET:"true",EXP_MACHINE_POOL: "true"} | ||
Variables map[string]string `json:"variables,omitempty"` | ||
|
||
ProviderStatus *operatorv1.ProviderStatus `json:",inline"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// CAPIProvider is the Schema for the CAPI Providers API. | ||
type CAPIProvider struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// +kubebuilder:example={name: aws, version: "v2.3.0", type: infrastructure, credentials: {rancherCloudCredential: user-credential}} | ||
Spec CAPIProviderSpec `json:"spec,omitempty"` | ||
|
||
// +kubebuilder:default={} | ||
Status CAPIProviderStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// CAPIProviderList contains a list of CAPIProviders. | ||
type CAPIProviderList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []CAPIProvider `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&CAPIProvider{}, &CAPIProviderList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright SUSE 2023. | ||
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 contains API Schema definitions for the turtles-capi.cattle.io v1alpha1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=turtles-capi.cattle.io | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects. | ||
GroupVersion = schema.GroupVersion{Group: "turtles-capi.cattle.io", Version: "v1alpha1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme. | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package v1alpha1 | ||
|
||
// ProviderName defines the designated provider infrastructure provider name. | ||
type ProviderName string | ||
|
||
const ( | ||
// AWSProvider is the name for the aws provider. | ||
AWSProvider ProviderName = "aws" | ||
// AzureProvider is the name for Azure provider. | ||
AzureProvider ProviderName = "azure" | ||
// GCPProvider is the name for the GCP provider. | ||
GCPProvider ProviderName = "gcp" | ||
// DockerProvider is the name for the docker provider. | ||
DockerProvider ProviderName = "docker" | ||
// RKE2Provider is the name for the RKE2 provider. | ||
RKE2Provider ProviderName = "rke2" | ||
) | ||
|
||
// ProviderType defines the type of the CAPI Provider. | ||
type ProviderType string | ||
|
||
const ( | ||
// InfrastructureProvider is the name for the infrastructure CAPI Provider. | ||
InfrastructureProvider ProviderType = "infrastructure" | ||
// CoreProvider is the name for core CAPI Provider. | ||
CoreProvider ProviderType = "core" | ||
// ControlPlaneProvider is the name for the controlPlane CAPI Provider. | ||
ControlPlaneProvider ProviderType = "controlPlane" | ||
// BootstrapProvider is the name for the bootstrap CAPI Provider. | ||
BootstrapProvider ProviderType = "bootstrap" | ||
// AddonProvider is the name for the addon CAPI Provider. | ||
AddonProvider ProviderType = "addon" | ||
) | ||
|
||
// ProviderState defines the current state of the CAPI Provider resource. | ||
type ProviderState string | ||
|
||
const ( | ||
// Pending status identifies a provder which has not yet started provisioning. | ||
Pending ProviderState = "Pending" | ||
// Provisioning status defines provider in a provisioning state. | ||
Provisioning ProviderState = "Provisioning" | ||
// Ready status identifies that the provider is ready to be used. | ||
Ready ProviderState = "Ready" | ||
// Failed status defines a failed state of provider provisioning. | ||
Failed ProviderState = "Failed" | ||
) |
Oops, something went wrong.