Skip to content

Commit

Permalink
Merge pull request #370 from Fedosin/feat-ipam-provider
Browse files Browse the repository at this point in the history
✨Add IPAM provider support
  • Loading branch information
k8s-ci-robot authored Jan 8, 2024
2 parents a3e3662 + 48b4cca commit 0b7c817
Show file tree
Hide file tree
Showing 21 changed files with 3,617 additions and 10 deletions.
16 changes: 16 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,20 @@ resources:
kind: InfrastructureProvider
path: sigs.k8s.io/cluster-api-operator/api/v1alpha2
version: v1alpha2
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: operator
kind: AddonProvider
path: sigs.k8s.io/cluster-api-operator/api/v1alpha2
version: v1alpha2
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: operator
kind: IPAMProvider
path: sigs.k8s.io/cluster-api-operator/api/v1alpha2
version: v1alpha2
version: "3"
59 changes: 59 additions & 0 deletions api/v1alpha2/ipamprovider_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2023 The Kubernetes Authors.
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 v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// IPAMProviderSpec defines the desired state of IPAMProvider.
type IPAMProviderSpec struct {
ProviderSpec `json:",inline"`
}

// IPAMProviderStatus defines the observed state of IPAMProvider.
type IPAMProviderStatus struct {
ProviderStatus `json:",inline"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="InstalledVersion",type="string",JSONPath=".status.installedVersion"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:storageversion

// IPAMProvider is the Schema for the IPAMProviders API.
type IPAMProvider struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IPAMProviderSpec `json:"spec,omitempty"`
Status IPAMProviderStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
objectTypes = append(objectTypes, &IPAMProvider{}, &IPAMProviderList{})
}
61 changes: 61 additions & 0 deletions api/v1alpha2/ipamprovider_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2023 The Kubernetes Authors.
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 v1alpha2

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

var _ GenericProvider = &IPAMProvider{}

func (p *IPAMProvider) GetConditions() clusterv1.Conditions {
return p.Status.Conditions
}

func (p *IPAMProvider) SetConditions(conditions clusterv1.Conditions) {
p.Status.Conditions = conditions
}

func (p *IPAMProvider) GetSpec() ProviderSpec {
return p.Spec.ProviderSpec
}

func (p *IPAMProvider) SetSpec(in ProviderSpec) {
p.Spec.ProviderSpec = in
}

func (p *IPAMProvider) GetStatus() ProviderStatus {
return p.Status.ProviderStatus
}

func (p *IPAMProvider) SetStatus(in ProviderStatus) {
p.Status.ProviderStatus = in
}

func (p *IPAMProvider) GetType() string {
return "ipam"
}

func (p *IPAMProviderList) GetItems() []GenericProvider {
providers := []GenericProvider{}

for index := range p.Items {
providers = append(providers, &p.Items[index])
}

return providers
}
91 changes: 91 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ func setupReconcilers(mgr ctrl.Manager) {
os.Exit(1)
}

if err := (&providercontroller.GenericProviderReconciler{
Provider: &operatorv1.IPAMProvider{},
ProviderList: &operatorv1.IPAMProviderList{},
Client: mgr.GetClient(),
Config: mgr.GetConfig(),
}).SetupWithManager(mgr, concurrency(concurrencyNumber)); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IPAMProvider")
os.Exit(1)
}

if err := (&healtchcheckcontroller.ProviderHealthCheckReconciler{
Client: mgr.GetClient(),
}).SetupWithManager(mgr, concurrency(concurrencyNumber)); err != nil {
Expand Down Expand Up @@ -293,6 +303,11 @@ func setupWebhooks(mgr ctrl.Manager) {
setupLog.Error(err, "unable to create webhook", "webhook", "AddonProvider")
os.Exit(1)
}

if err := (&webhook.IPAMProviderWebhook{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IPAMProvider")
os.Exit(1)
}
}

func concurrency(c int) controller.Options {
Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type deleteOptions struct {
bootstrapProviders []string
controlPlaneProviders []string
infrastructureProviders []string
// ipamProviders []string
ipamProviders []string
// runtimeExtensionProviders []string
addonProviders []string
includeNamespace bool
Expand Down Expand Up @@ -106,8 +106,8 @@ func init() {
"Bootstrap providers and versions (e.g. kubeadm:v1.1.5) to delete from the management cluster")
deleteCmd.Flags().StringSliceVarP(&deleteOpts.controlPlaneProviders, "control-plane", "c", nil,
"ControlPlane providers and versions (e.g. kubeadm:v1.1.5) to delete from the management cluster")
// deleteCmd.Flags().StringSliceVar(&deleteOpts.ipamProviders, "ipam", nil,
// "IPAM providers and versions (e.g. infoblox:v0.0.1) to delete from the management cluster")
deleteCmd.Flags().StringSliceVar(&deleteOpts.ipamProviders, "ipam", nil,
"IPAM providers and versions (e.g. infoblox:v0.0.1) to delete from the management cluster")
// deleteCmd.Flags().StringSliceVar(&deleteOpts.runtimeExtensionProviders, "runtime-extension", nil,
// "Runtime extension providers and versions (e.g. test:v0.0.1) to delete from the management cluster")
deleteCmd.Flags().StringSliceVar(&deleteOpts.addonProviders, "addon", nil,
Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type initOptions struct {
bootstrapProviders []string
controlPlaneProviders []string
infrastructureProviders []string
// ipamProviders []string
ipamProviders []string
// runtimeExtensionProviders []string
addonProviders []string
targetNamespace string
Expand Down Expand Up @@ -102,8 +102,8 @@ func init() {
"Bootstrap providers and versions (e.g. kubeadm:v1.1.5) to add to the management cluster. If unspecified, Kubeadm bootstrap provider's latest release is used.")
initCmd.PersistentFlags().StringSliceVarP(&initOpts.controlPlaneProviders, "control-plane", "c", nil,
"Control plane providers and versions (e.g. kubeadm:v1.1.5) to add to the management cluster. If unspecified, the Kubeadm control plane provider's latest release is used.")
// initCmd.PersistentFlags().StringSliceVar(&initOpts.ipamProviders, "ipam", nil,
// "IPAM providers and versions (e.g. infoblox:v0.0.1) to add to the management cluster.")
initCmd.PersistentFlags().StringSliceVar(&initOpts.ipamProviders, "ipam", nil,
"IPAM providers and versions (e.g. infoblox:v0.0.1) to add to the management cluster.")
// initCmd.PersistentFlags().StringSliceVar(&initOpts.runtimeExtensionProviders, "runtime-extension", nil,
// "Runtime extension providers and versions (e.g. test:v0.0.1) to add to the management cluster.")
initCmd.PersistentFlags().StringSliceVar(&initOpts.addonProviders, "addon", nil,
Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/cmd/upgrade_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type upgradeApplyOptions struct {
bootstrapProviders []string
controlPlaneProviders []string
infrastructureProviders []string
// ipamProviders []string
ipamProviders []string
// runtimeExtensionProviders []string
addonProviders []string
waitProviders bool
Expand Down Expand Up @@ -80,8 +80,8 @@ func init() {
"Bootstrap providers instance and versions (e.g. kubeadm:v1.1.5) to upgrade to. This flag can be used as alternative to --contract.")
upgradeApplyCmd.Flags().StringSliceVarP(&upgradeApplyOpts.controlPlaneProviders, "control-plane", "c", nil,
"ControlPlane providers instance and versions (e.g. kubeadm:v1.1.5) to upgrade to. This flag can be used as alternative to --contract.")
// upgradeApplyCmd.Flags().StringSliceVar(&upgradeApplyOpts.ipamProviders, "ipam", nil,
// "IPAM providers and versions (e.g. infoblox:v0.0.1) to upgrade to. This flag can be used as alternative to --contract.")
upgradeApplyCmd.Flags().StringSliceVar(&upgradeApplyOpts.ipamProviders, "ipam", nil,
"IPAM providers and versions (e.g. infoblox:v0.0.1) to upgrade to. This flag can be used as alternative to --contract.")
// upgradeApplyCmd.Flags().StringSliceVar(&upgradeApplyOpts.runtimeExtensionProviders, "runtime-extension", nil,
// "Runtime extension providers and versions (e.g. test:v0.0.1) to upgrade to. This flag can be used as alternative to --contract.")
upgradeApplyCmd.Flags().StringSliceVar(&upgradeApplyOpts.addonProviders, "addon", nil,
Expand Down
Loading

0 comments on commit 0b7c817

Please sign in to comment.