Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SubnetIP resource #69

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,13 @@ resources:
kind: ReservedIP
path: github.com/onmetal/onmetal-api/apis/network/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: onmetal.de
group: network
kind: SubnetIP
path: github.com/onmetal/onmetal-api/apis/network/v1alpha1
version: v1alpha1
version: "3"
9 changes: 9 additions & 0 deletions apis/common/v1alpha1/classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ type ScopeReference struct {
// Scope is the absolute scope path
Scope string `json:"scope"`
}

// KindReference defines an object with its kind and API group and its scope reference
type KindReference struct {
// Kind is the kind of the object
Kind string `json:"kind"`
// APIGroup is the API group of the object
APIGroup string `json:"apigroup"`
ScopeReference `json:",inline"`
}
76 changes: 76 additions & 0 deletions apis/network/v1alpha1/subnetip_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2021.

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 (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net"
)

// SubnetIPSpec defines the desired state of SubnetIP
type SubnetIPSpec struct {
// IP is the used IP in a given subnet
IP net.IP `json:"ip"`
// Subnet is the subnet of the IP
Subnet common.ScopeReference `json:"subnet"`
// Target is the resource the IP is assigned to
Target common.KindReference `json:"target"`
}

// SubnetIPStatus defines the observed state of SubnetIP
type SubnetIPStatus struct {
common.StateFields `json:",inline"`
}

const (
SubnetIPStateAssigned = "Assigned"
SubnetIPStateUnassigned = "Unassigned"
SubnetIPStateInvalid = "Invalid"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="IP",type=string,JSONPath=`.spec.ip`
//+kubebuilder:printcolumn:name="Subnet",type=string,JSONPath=`.spec.subnet.name`
//+kubebuilder:printcolumn:name="SubnetScope",type=string,JSONPath=`.spec.subnet.scope`
//+kubebuilder:printcolumn:name="Target",type=string,JSONPath=`.spec.target.name`
//+kubebuilder:printcolumn:name="TargetKind",type=string,JSONPath=`.spec.target.kind`
//+kubebuilder:printcolumn:name="StateFields",type=string,JSONPath=`.status.state`
//+kubebuilder:printcolumn:name="Age",type=string,JSONPath=`.metadata.CreationTimestamp`

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

Spec SubnetIPSpec `json:"spec,omitempty"`
Status SubnetIPStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&SubnetIP{}, &SubnetIPList{})
}
97 changes: 97 additions & 0 deletions apis/network/v1alpha1/zz_generated.deepcopy.go

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

124 changes: 124 additions & 0 deletions config/crd/bases/network.onmetal.de_subnetips.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: subnetips.network.onmetal.de
spec:
group: network.onmetal.de
names:
kind: SubnetIP
listKind: SubnetIPList
plural: subnetips
singular: subnetip
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.ip
name: IP
type: string
- jsonPath: .spec.subnet.name
name: Subnet
type: string
- jsonPath: .spec.subnet.scope
name: SubnetScope
type: string
- jsonPath: .spec.target.name
name: Target
type: string
- jsonPath: .spec.target.kind
name: TargetKind
type: string
- jsonPath: .status.state
name: StateFields
type: string
- jsonPath: .metadata.CreationTimestamp
name: Age
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: SubnetIP is the Schema for the subnetips 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: SubnetIPSpec defines the desired state of SubnetIP
properties:
ip:
description: IP is the used IP in a given subnet
format: byte
type: string
subnet:
description: Subnet is the subnet of the IP
properties:
name:
description: Name is the name of the scope
type: string
scope:
description: Scope is the absolute scope path
type: string
required:
- name
- scope
type: object
target:
description: Target is the resource the IP is assigned to
properties:
apigroup:
description: APIGroup is the API group of the object
type: string
kind:
description: Kind is the kind of the object
type: string
name:
description: Name is the name of the scope
type: string
scope:
description: Scope is the absolute scope path
type: string
required:
- apigroup
- kind
- name
- scope
type: object
required:
- ip
- subnet
- target
type: object
status:
description: SubnetIPStatus defines the observed state of SubnetIP
properties:
message:
description: Message contains a message for the corresponding state
type: string
state:
description: State indicates the state of a resource
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resources:
- bases/storage.onmetal.de_volumes.yaml
- bases/storage.onmetal.de_volumeattachments.yaml
- bases/network.onmetal.de_reservedips.yaml
- bases/network.onmetal.de_subnetips.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -31,6 +32,7 @@ patchesStrategicMerge:
#- patches/webhook_in_volumes.yaml
#- patches/webhook_in_volumeattachments.yaml
#- patches/webhook_in_reservedips.yaml
#- patches/webhook_in_subnetips.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -47,6 +49,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_volumes.yaml
#- patches/cainjection_in_volumeattachments.yaml
#- patches/cainjection_in_reservedips.yaml
#- patches/cainjection_in_subnetips.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_subnetips.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: subnetips.network.onmetal.de
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_subnetips.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: subnetips.network.onmetal.de
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
Loading