Skip to content

Commit

Permalink
Added Subnet CRD (#53)
Browse files Browse the repository at this point in the history
* feat: add subnet support

* added printcolumns

* fix: NStorage: Search subnets in children subnets too

* fix: subnet: right message in status field

* fix: subnet: fields validation

* fix: allocation: right message in status field

* fix: site: right message in status field

* fix: site: right message in status field

* fix: finalizers names for delete

* refactor: update go version from 1.16 to 1.17

* fix: subnet example

* typos

* added subnet samples

* update subnet sample

Co-authored-by: Artashes Balabekyan <[email protected]>
  • Loading branch information
pogossian and artashesbalabekyan authored Feb 2, 2022
1 parent 50c921d commit 745a016
Show file tree
Hide file tree
Showing 37 changed files with 1,570 additions and 12 deletions.
18 changes: 18 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,22 @@ resources:
kind: AllocationMeta
path: github.com/netrisai/netris-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: netris.ai
group: k8s
kind: Subnet
path: github.com/netrisai/netris-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: netris.ai
group: k8s
kind: SubnetMeta
path: github.com/netrisai/netris-operator/api/v1alpha1
version: v1alpha1
version: "3"
1 change: 1 addition & 0 deletions api/v1alpha1/allocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type AllocationStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.spec.prefix`
// +kubebuilder:printcolumn:name="Tenant",type=string,JSONPath=`.spec.tenant`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// Allocation is the Schema for the allocations API
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/site_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type SiteSpec struct {
// +kubebuilder:printcolumn:name="ROH Routing Profile",type=string,JSONPath=`.spec.rohRoutingProfile`
// +kubebuilder:printcolumn:name="Site Mesh",type=string,JSONPath=`.spec.siteMesh`
// +kubebuilder:printcolumn:name="ACL Default Policy",type=string,JSONPath=`.spec.aclDefaultPolicy`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// Site is the Schema for the sites API
Expand Down
82 changes: 82 additions & 0 deletions api/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2021. Netris, Inc.
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"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// SubnetSpec defines the desired state of Subnet
type SubnetSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:Pattern=`(^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/([0-9]|[12]\d|3[0-2]))?$)|(^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?(\/([1-9]|[1-5][0-9]|6[0-4]))?$)`
Prefix string `json:"prefix,omitempty"`
Tenant string `json:"tenant,omitempty"`

// +kubebuilder:validation:Enum=common;loopback;management;load-balancer;nat;inactive
Purpose string `json:"purpose,omitempty"`

// +kubebuilder:validation:Pattern=`^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$`
DefaultGateway string `json:"defaultGateway,omitempty"`
Sites []string `json:"sites,omitempty"`
}

// SubnetStatus defines the observed state of Subnet
type SubnetStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Prefix",type=string,JSONPath=`.spec.prefix`
// +kubebuilder:printcolumn:name="Tenant",type=string,JSONPath=`.spec.tenant`
// +kubebuilder:printcolumn:name="Purpose",type=string,JSONPath=`.spec.purpose`
// +kubebuilder:printcolumn:name="Sites",type=string,JSONPath=`.spec.sites`
// +kubebuilder:printcolumn:name="Default Gateway",type=string,JSONPath=`.spec.defaultGateway`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

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

Spec SubnetSpec `json:"spec,omitempty"`
Status SubnetStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Subnet{}, &SubnetList{})
}
72 changes: 72 additions & 0 deletions api/v1alpha1/subnetmeta_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2021. Netris, Inc.
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"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// SubnetMetaSpec defines the desired state of SubnetMeta
type SubnetMetaSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Imported bool `json:"imported"`
Reclaim bool `json:"reclaimPolicy"`
SubnetCRGeneration int64 `json:"subnetGeneration"`
ID int `json:"id"`
SubnetName string `json:"subnetName"`

Prefix string `json:"prefix,omitempty"`
TenantID int `json:"tenantid,omitempty"`
Purpose string `json:"purpose,omitempty"`
DefaultGateway string `json:"defaultGateway,omitempty"`
Sites []int `json:"sites,omitempty"`
}

// SubnetMetaStatus defines the observed state of SubnetMeta
type SubnetMetaStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

Spec SubnetMetaSpec `json:"spec,omitempty"`
Status SubnetMetaStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&SubnetMeta{}, &SubnetMetaList{})
}
188 changes: 188 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.

2 changes: 1 addition & 1 deletion calicowatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (w *Watcher) deleteProcess() error {
if err := w.Calico.DeleteBGPPeer(netrisPeer, w.restClient); err != nil {
return err
}
logger.Info("netris-controller pee deleted", "deleteMode", w.data.deleteMode)
logger.Info("Peers in netris-controller are deleted", "deleteMode", w.data.deleteMode)
}

return nil
Expand Down
Loading

0 comments on commit 745a016

Please sign in to comment.