diff --git a/Makefile b/Makefile index 9a7a4cca73..7688d2c546 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ rbacs: controller-gen rm -f deployments/liqo/files/* $(CONTROLLER_GEN) paths="./internal/liqonet/route-operator" rbac:roleName=liqo-route output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-route-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-route-ClusterRole.yaml deployments/liqo/files/liqo-route-Role.yaml $(CONTROLLER_GEN) paths="./internal/liqonet/tunnel-operator" rbac:roleName=liqo-gateway output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-gateway-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-gateway-ClusterRole.yaml deployments/liqo/files/liqo-gateway-Role.yaml - $(CONTROLLER_GEN) paths="./internal/liqonet/network-manager/..." rbac:roleName=liqo-network-manager output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-network-manager-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-network-manager-ClusterRole.yaml deployments/liqo/files/liqo-network-manager-Role.yaml + $(CONTROLLER_GEN) paths="{./internal/liqonet/network-manager/...,./pkg/liqonet/...}" rbac:roleName=liqo-network-manager output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-network-manager-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-network-manager-ClusterRole.yaml deployments/liqo/files/liqo-network-manager-Role.yaml $(CONTROLLER_GEN) paths="./internal/crdReplicator" rbac:roleName=liqo-crd-replicator output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-crd-replicator-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-crd-replicator-ClusterRole.yaml deployments/liqo/files/liqo-crd-replicator-Role.yaml $(CONTROLLER_GEN) paths="./pkg/discoverymanager" rbac:roleName=liqo-discovery output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-discovery-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-discovery-ClusterRole.yaml deployments/liqo/files/liqo-discovery-Role.yaml $(CONTROLLER_GEN) paths="./internal/auth-service" rbac:roleName=liqo-auth-service output:rbac:stdout | awk -v RS="---\n" 'NR>1{f="./deployments/liqo/files/liqo-auth-" $$4 ".yaml";printf "%s",$$0 > f; close(f)}' && sed -i -n '/rules/,$$p' deployments/liqo/files/liqo-auth-ClusterRole.yaml deployments/liqo/files/liqo-auth-Role.yaml diff --git a/apis/networking/v1alpha1/common_types.go b/apis/networking/v1alpha1/common_types.go new file mode 100644 index 0000000000..15e3ffb43f --- /dev/null +++ b/apis/networking/v1alpha1/common_types.go @@ -0,0 +1,29 @@ +// Copyright 2019-2023 The Liqo 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 v1alpha1 contains API Schema definitions for the networking v1alpha1 API group. +// +//nolint:lll // ignore long lines given by Kubebuilder marker annotations. +package v1alpha1 + +// 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. + +// CIDR defines a syntax validated CIDR. +// +kubebuilder:validation:Pattern=`^(([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]$|[1-2][0-9]$|3[0-2]$)` +type CIDR string + +// IP defines a syntax validated IP. +// +kubebuilder:validation:Pattern=`^(([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])` +type IP string diff --git a/apis/networking/v1alpha1/configuration_types.go b/apis/networking/v1alpha1/configuration_types.go index 94b24ae195..c13b09cbcc 100644 --- a/apis/networking/v1alpha1/configuration_types.go +++ b/apis/networking/v1alpha1/configuration_types.go @@ -34,18 +34,18 @@ var ConfigurationGroupResource = schema.GroupResource{Group: GroupVersion.Group, // ConfigurationGroupVersionResource is groupResourceVersion used to register these objects. var ConfigurationGroupVersionResource = GroupVersion.WithResource(ConfigurationResource) -// CIDR defines the CIDR of the cluster. -type CIDR struct { +// ClusterConfigCIDR defines the CIDR of the cluster. +type ClusterConfigCIDR struct { // Pod CIDR of the cluster. - Pod string `json:"pod,omitempty"` + Pod CIDR `json:"pod,omitempty"` // External CIDR of the cluster. - External string `json:"external,omitempty"` + External CIDR `json:"external,omitempty"` } // ClusterConfig defines the configuration of a cluster. type ClusterConfig struct { // CIDR of the cluster. - CIDR CIDR `json:"cidr,omitempty"` + CIDR ClusterConfigCIDR `json:"cidr,omitempty"` } // ConfigurationSpec defines the desired state of Configuration. diff --git a/apis/networking/v1alpha1/gatewayserver_types.go b/apis/networking/v1alpha1/gatewayserver_types.go index 9929c9ec72..77f1b45f62 100644 --- a/apis/networking/v1alpha1/gatewayserver_types.go +++ b/apis/networking/v1alpha1/gatewayserver_types.go @@ -58,7 +58,7 @@ type GatewayServerSpec struct { // EndpointStatus defines the observed state of the endpoint. type EndpointStatus struct { // Addresses specifies the addresses of the endpoint. - Addresses []string `json:"addresses,omitempty"` + Addresses []IP `json:"addresses,omitempty"` // Port specifies the port of the endpoint. Port int32 `json:"port,omitempty"` // Protocol specifies the protocol of the endpoint. diff --git a/apis/networking/v1alpha1/zz_generated.deepcopy.go b/apis/networking/v1alpha1/zz_generated.deepcopy.go index 1bbcc2e4bb..840a156d1f 100644 --- a/apis/networking/v1alpha1/zz_generated.deepcopy.go +++ b/apis/networking/v1alpha1/zz_generated.deepcopy.go @@ -48,21 +48,6 @@ func (in *AddRemove) DeepCopy() *AddRemove { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CIDR) DeepCopyInto(out *CIDR) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CIDR. -func (in *CIDR) DeepCopy() *CIDR { - if in == nil { - return nil - } - out := new(CIDR) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClientTemplate) DeepCopyInto(out *ClientTemplate) { *out = *in @@ -96,6 +81,21 @@ func (in *ClusterConfig) DeepCopy() *ClusterConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterConfigCIDR) DeepCopyInto(out *ClusterConfigCIDR) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfigCIDR. +func (in *ClusterConfigCIDR) DeepCopy() *ClusterConfigCIDR { + if in == nil { + return nil + } + out := new(ClusterConfigCIDR) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Configuration) DeepCopyInto(out *Configuration) { *out = *in @@ -340,7 +340,7 @@ func (in *EndpointStatus) DeepCopyInto(out *EndpointStatus) { *out = *in if in.Addresses != nil { in, out := &in.Addresses, &out.Addresses - *out = make([]string, len(*in)) + *out = make([]IP, len(*in)) copy(*out, *in) } if in.Protocol != nil { diff --git a/cmd/liqonet/network-manager.go b/cmd/liqonet/network-manager.go index 2883152346..9841da876c 100644 --- a/cmd/liqonet/network-manager.go +++ b/cmd/liqonet/network-manager.go @@ -30,6 +30,7 @@ import ( "github.com/liqotech/liqo/internal/liqonet/network-manager/netcfgcreator" "github.com/liqotech/liqo/internal/liqonet/network-manager/tunnelendpointcreator" liqoconst "github.com/liqotech/liqo/pkg/consts" + configurationcontroller "github.com/liqotech/liqo/pkg/liqonet/configuration-controller" liqonetIpam "github.com/liqotech/liqo/pkg/liqonet/ipam" liqonetutils "github.com/liqotech/liqo/pkg/liqonet/utils" "github.com/liqotech/liqo/pkg/utils/args" @@ -109,6 +110,8 @@ func runNetworkManager(commonFlags *liqonetCommonFlags, managerFlags *networkMan ExternalCIDR: externalCIDR, } + cfgr := configurationcontroller.NewConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("configuration-controller")) + if err = tec.SetupWithManager(mgr); err != nil { klog.Errorf("unable to create controller TunnelEndpointCreator: %s", err) os.Exit(1) @@ -119,6 +122,11 @@ func runNetworkManager(commonFlags *liqonetCommonFlags, managerFlags *networkMan os.Exit(1) } + if err = cfgr.SetupWithManager(mgr); err != nil { + klog.Errorf("unable to create controller ConfigurationReconciler: %s", err) + os.Exit(1) + } + klog.Info("starting manager as liqo-network-manager") if err := mgr.Start(tec.SetupSignalHandlerForTunEndCreator()); err != nil { klog.Errorf("an error occurred while starting manager: %s", err) diff --git a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml index 3beb860377..ef6b444ee9 100644 --- a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml +++ b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_configurations.yaml @@ -47,9 +47,11 @@ spec: properties: external: description: External CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string pod: description: Pod CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string type: object type: object @@ -62,9 +64,11 @@ spec: properties: external: description: External CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string pod: description: Pod CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string type: object type: object @@ -76,9 +80,11 @@ spec: properties: external: description: External CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string pod: description: Pod CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string type: object type: object @@ -95,9 +101,11 @@ spec: properties: external: description: External CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string pod: description: Pod CIDR of the cluster. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|3[0-1]) type: string type: object type: object diff --git a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml index abf0861514..772cc68854 100644 --- a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml +++ b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_connections.yaml @@ -88,6 +88,8 @@ spec: addresses: description: Addresses specifies the addresses of the endpoint. items: + description: IP defines a syntax validated IP. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5]) type: string type: array port: diff --git a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_gatewayservers.yaml b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_gatewayservers.yaml index 0b73a9b025..81b76b25c7 100644 --- a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_gatewayservers.yaml +++ b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_gatewayservers.yaml @@ -105,6 +105,8 @@ spec: addresses: description: Addresses specifies the addresses of the endpoint. items: + description: IP defines a syntax validated IP. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5]) type: string type: array port: diff --git a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_wggatewayservers.yaml b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_wggatewayservers.yaml index 77d8105c15..f4128a79b7 100644 --- a/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_wggatewayservers.yaml +++ b/deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_wggatewayservers.yaml @@ -8966,6 +8966,8 @@ spec: addresses: description: Addresses specifies the addresses of the endpoint. items: + description: IP defines a syntax validated IP. + pattern: (([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5]) type: string type: array port: diff --git a/deployments/liqo/files/liqo-network-manager-ClusterRole.yaml b/deployments/liqo/files/liqo-network-manager-ClusterRole.yaml index 8fb45b2f1e..174008704f 100644 --- a/deployments/liqo/files/liqo-network-manager-ClusterRole.yaml +++ b/deployments/liqo/files/liqo-network-manager-ClusterRole.yaml @@ -84,3 +84,12 @@ rules: - patch - update - watch +- apiGroups: + - networking.liqo.io + resources: + - configuration + verbs: + - get + - list + - update + - watch diff --git a/pkg/liqonet/configuration-controller/configuration-controller.go b/pkg/liqonet/configuration-controller/configuration-controller.go new file mode 100644 index 0000000000..3601c1d6bb --- /dev/null +++ b/pkg/liqonet/configuration-controller/configuration-controller.go @@ -0,0 +1,71 @@ +// Copyright 2019-2023 The Liqo 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 configurationcontroller + +import ( + "context" + "fmt" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/tools/record" + "k8s.io/klog/v2" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1" +) + +// ConfigurationReconciler manage Configuration lifecycle. +type ConfigurationReconciler struct { + client.Client + Scheme *runtime.Scheme + EventsRecorder record.EventRecorder +} + +// NewConfigurationReconciler returns a new ConfigurationReconciler. +func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder) *ConfigurationReconciler { + return &ConfigurationReconciler{ + Client: cl, + Scheme: s, + EventsRecorder: er, + } +} + +// cluster-role +// +kubebuilder:rbac:groups=networking.liqo.io,resources=configuration,verbs=get;list;watch;update + +// Reconcile manage NamespaceMaps associated with the virtual-node. +func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + configuration := &networkingv1alpha1.Configuration{} + if err := r.Get(ctx, req.NamespacedName, configuration); err != nil { + if apierrors.IsNotFound(err) { + klog.Infof("There is no a configuration called '%s' in '%s'", req.Name, req.Namespace) + return ctrl.Result{}, nil + } + return ctrl.Result{}, fmt.Errorf(" %w --> Unable to get the configuration '%s'", err, req.Name) + } + + klog.Info("Reconciling configuration") + klog.Infof("Configuration: %s", configuration) + + return ctrl.Result{}, nil +} + +// SetupWithManager register the ConfigurationReconciler to the manager. +func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&networkingv1alpha1.Configuration{}).Complete(r) +} diff --git a/pkg/liqonet/configuration-controller/doc.go b/pkg/liqonet/configuration-controller/doc.go new file mode 100644 index 0000000000..86a51f96a2 --- /dev/null +++ b/pkg/liqonet/configuration-controller/doc.go @@ -0,0 +1,15 @@ +// Copyright 2019-2023 The Liqo 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 configurationcontroller diff --git a/samples/configuration1.yaml b/samples/configuration1.yaml new file mode 100644 index 0000000000..8015014956 --- /dev/null +++ b/samples/configuration1.yaml @@ -0,0 +1,16 @@ +apiVersion: networking.liqo.io/v1alpha1 +kind: Configuration +metadata: + name: configuration-sample +spec: + local: + cidr: + external: 0.0.550.0/3643453 + pod: 10.3.3.3/4 + remote: + cidr: + external: 6.6.6.6/3 + pod: 255.255.255.255/10 + + +