-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Deploy IPAM with clusterctl - Reconsile CAPI's ipaddressclaims with this managers ippools Signed-off-by: peppi-lotta <[email protected]>
- Loading branch information
1 parent
910a3b2
commit 4fcd34f
Showing
47 changed files
with
5,333 additions
and
532 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
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
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,19 @@ | ||
/* | ||
Copyright 2019 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 | ||
|
||
func (*IPPool) Hub() {} |
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,23 @@ | ||
/* | ||
Copyright 2019 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 contains API Schema definitions for the metal3 v1alpha2 API group | ||
// +k8s:openapi-gen=true | ||
// +k8s:deepcopy-gen=package,register | ||
// +k8s:defaulter-gen=TypeMeta | ||
// +kubebuilder:object:generate=true | ||
// +groupName=ipam.metal3.io | ||
package v1alpha2 |
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,53 @@ | ||
/* | ||
Copyright 2019 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 contains API Schema definitions for the infrastructure v1alpha2 API group | ||
// +kubebuilder:object:generate=true | ||
// +k8s:openapi-gen=true | ||
// +k8s:deepcopy-gen=package,register | ||
// +k8s:defaulter-gen=TypeMeta | ||
// +groupName=ipam.metal3.io | ||
package v1alpha2 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects. | ||
GroupVersion = schema.GroupVersion{Group: "ipam.metal3.io", Version: "v1alpha2"} | ||
|
||
/// schemeBuilder is used to add go types to the GroupVersionKind scheme. | ||
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = schemeBuilder.AddToScheme | ||
|
||
objectTypes = []runtime.Object{} | ||
) | ||
|
||
func addKnownTypes(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes(GroupVersion, objectTypes...) | ||
metav1.AddToGroupVersion(scheme, GroupVersion) | ||
return nil | ||
} | ||
|
||
// Resource is required by pkg/client/listers/... | ||
// func Resource(resource string) schema.GroupResource { | ||
// return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
// } |
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,77 @@ | ||
/* | ||
Copyright 2019 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 ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
// DataFinalizer allows IPAddressReconciler to clean up resources | ||
// associated with IPAddress before removing it from the apiserver. | ||
IPAddressFinalizer = "ipaddress.ipam.metal3.io" | ||
) | ||
|
||
// IPAddressSpec defines the desired state of IPAddress. | ||
type IPAddressSpec struct { | ||
|
||
// Claim points to the object the IPClaim was created for. | ||
Claim corev1.ObjectReference `json:"claim"` | ||
|
||
// Pool is the IPPool this was generated from. | ||
Pool corev1.ObjectReference `json:"pool"` | ||
|
||
// +kubebuilder:validation:Maximum=128 | ||
// Prefix is the mask of the network as integer (max 128) | ||
Prefix int `json:"prefix,omitempty"` | ||
|
||
// Gateway is the gateway ip address | ||
Gateway *string `json:"gateway,omitempty"` | ||
|
||
// Address contains the IP address | ||
Address string `json:"address"` | ||
|
||
// DNSServers is the list of dns servers | ||
DNSServers []string `json:"dnsServers,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
// +kubebuilder:resource:path=ipaddresses,scope=Namespaced,categories=metal3,shortName=ipa;ipaddress;m3ipa;m3ipaddress;m3ipaddresses;metal3ipa;metal3ipaddress;metal3ipaddresses | ||
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Metal3IPAddress" | ||
// +kubebuilder:storageversion | ||
// +kubebuilder:object:root=true | ||
// IPAddress is the Schema for the ipaddresses API. | ||
type IPAddress struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec IPAddressSpec `json:"spec,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// IPAddressList contains a list of IPAddress. | ||
type IPAddressList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []IPAddress `json:"items"` | ||
} | ||
|
||
func init() { | ||
objectTypes = append(objectTypes, &IPAddress{}, &IPAddressList{}) | ||
} |
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,159 @@ | ||
/* | ||
Copyright 2020 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 ( | ||
"github.com/pkg/errors" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
func (c *IPAddress) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(c). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:verbs=create;update,path=/validate-ipam-metal3-io-v1alpha2-ipaddress,mutating=false,failurePolicy=fail,groups=ipam.metal3.io,resources=ipaddresses,versions=v1alpha2,name=validation.ipaddress.ipam.metal3.io,matchPolicy=Equivalent,sideEffects=None,admissionReviewVersions=v1;v1beta1 | ||
// +kubebuilder:webhook:verbs=create;update,path=/mutate-ipam-metal3-io-v1alpha2-ipaddress,mutating=true,failurePolicy=fail,groups=ipam.metal3.io,resources=ipaddresses,versions=v1alpha2,name=default.ipaddress.ipam.metal3.io,matchPolicy=Equivalent,sideEffects=None,admissionReviewVersions=v1;v1beta1 | ||
|
||
var _ webhook.Defaulter = &IPAddress{} | ||
var _ webhook.Validator = &IPAddress{} | ||
|
||
func (c *IPAddress) Default() { | ||
} | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type. | ||
func (c *IPAddress) ValidateCreate() (admission.Warnings, error) { | ||
allErrs := field.ErrorList{} | ||
if c.Spec.Pool.Name == "" { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "pool", "name"), | ||
c.Spec.Pool.Name, | ||
"cannot be empty", | ||
), | ||
) | ||
} | ||
|
||
if c.Spec.Claim.Name == "" { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "claim", "name"), | ||
c.Spec.Claim.Name, | ||
"cannot be empty", | ||
), | ||
) | ||
} | ||
|
||
if c.Spec.Address == "" { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "address"), | ||
c.Spec.Address, | ||
"cannot be empty", | ||
), | ||
) | ||
} | ||
|
||
if len(allErrs) == 0 { | ||
return nil, nil | ||
} | ||
return nil, apierrors.NewInvalid(GroupVersion.WithKind("IPAddress").GroupKind(), c.Name, allErrs) | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. | ||
func (c *IPAddress) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { | ||
allErrs := field.ErrorList{} | ||
oldIPAddress, ok := old.(*IPAddress) | ||
if !ok || oldIPAddress == nil { | ||
return nil, apierrors.NewInternalError(errors.New("unable to convert existing object")) | ||
} | ||
|
||
if c.Spec.Address != oldIPAddress.Spec.Address { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "address"), | ||
c.Spec.Address, | ||
"cannot be modified", | ||
), | ||
) | ||
} | ||
|
||
if c.Spec.Pool.Name != oldIPAddress.Spec.Pool.Name { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "pool"), | ||
c.Spec.Pool, | ||
"cannot be modified", | ||
), | ||
) | ||
} else if c.Spec.Pool.Namespace != oldIPAddress.Spec.Pool.Namespace { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "pool"), | ||
c.Spec.Pool, | ||
"cannot be modified", | ||
), | ||
) | ||
} else if c.Spec.Pool.Kind != oldIPAddress.Spec.Pool.Kind { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "pool"), | ||
c.Spec.Pool, | ||
"cannot be modified", | ||
), | ||
) | ||
} | ||
|
||
if c.Spec.Claim.Name != oldIPAddress.Spec.Claim.Name { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "claim"), | ||
c.Spec.Claim, | ||
"cannot be modified", | ||
), | ||
) | ||
} else if c.Spec.Claim.Namespace != oldIPAddress.Spec.Claim.Namespace { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "claim"), | ||
c.Spec.Claim, | ||
"cannot be modified", | ||
), | ||
) | ||
} else if c.Spec.Claim.Kind != oldIPAddress.Spec.Claim.Kind { | ||
allErrs = append(allErrs, | ||
field.Invalid( | ||
field.NewPath("spec", "claim"), | ||
c.Spec.Claim, | ||
"cannot be modified", | ||
), | ||
) | ||
} | ||
|
||
if len(allErrs) == 0 { | ||
return nil, nil | ||
} | ||
return nil, apierrors.NewInvalid(GroupVersion.WithKind("IPAddress").GroupKind(), c.Name, allErrs) | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. | ||
func (c *IPAddress) ValidateDelete() (admission.Warnings, error) { | ||
return nil, nil | ||
} |
Oops, something went wrong.