Skip to content

Commit

Permalink
Configuration controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Sep 29, 2023
1 parent 320f059 commit 0b99353
Show file tree
Hide file tree
Showing 27 changed files with 572 additions and 52 deletions.
6 changes: 4 additions & 2 deletions apis/ipam/v1alpha1/ip_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
)

var (
Expand Down Expand Up @@ -45,7 +47,7 @@ type ServiceTemplate struct {
// IPSpec defines a local IP.
type IPSpec struct {
// IP is the local IP.
IP string `json:"ip"`
IP networkingv1alpha1.IP `json:"ip"`
// ServiceTemplate contains the template to create the associated service (and endpointslice) for the IP endopoint.
// If empty the creation of the service is disabled (default).
// +kubebuilder:validation:Optional
Expand All @@ -55,7 +57,7 @@ type IPSpec struct {
// IPStatus defines remapped IPs.
type IPStatus struct {
// IPMappings contains the mapping of the local IP for each remote cluster.
IPMappings map[string]string `json:"ipMappings,omitempty"`
IPMappings map[string]networkingv1alpha1.IP `json:"ipMappings,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
6 changes: 4 additions & 2 deletions apis/ipam/v1alpha1/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

v1alpha1networking "github.com/liqotech/liqo/apis/networking/v1alpha1"
)

var (
Expand All @@ -36,13 +38,13 @@ var (
// NetworkSpec defines the desired state of Network.
type NetworkSpec struct {
// CIDR is the desired CIDR for the remote cluster.
CIDR string `json:"cidr"`
CIDR v1alpha1networking.CIDR `json:"cidr"`
}

// NetworkStatus defines the observed state of Network.
type NetworkStatus struct {
// CIDR is the remapped CIDR for the remote cluster.
CIDR string `json:"cidr,omitempty"`
CIDR v1alpha1networking.CIDR `json:"cidr,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
3 changes: 2 additions & 1 deletion apis/ipam/v1alpha1/zz_generated.deepcopy.go

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

37 changes: 37 additions & 0 deletions apis/networking/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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

func (c CIDR) String() string {
return string(c)
}

// 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

func (i IP) String() string {
return string(i)
}
10 changes: 5 additions & 5 deletions apis/networking/v1alpha1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions apis/networking/v1alpha1/zz_generated.deepcopy.go

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

8 changes: 8 additions & 0 deletions cmd/liqo-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ import (
discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1"
netv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
offloadingv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1"
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
virtualkubeletv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
"github.com/liqotech/liqo/cmd/virtual-kubelet/root"
"github.com/liqotech/liqo/pkg/consts"
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
configurationcontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/external-network/configuration-controller"
foreignclusteroperator "github.com/liqotech/liqo/pkg/liqo-controller-manager/foreign-cluster-operator"
ipctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/ip-controller"
mapsctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/namespacemap-controller"
Expand Down Expand Up @@ -107,6 +109,7 @@ func init() {
_ = offloadingv1alpha1.AddToScheme(scheme)
_ = virtualkubeletv1alpha1.AddToScheme(scheme)
_ = ipamv1alpha1.AddToScheme(scheme)
_ = networkingv1alpha1.AddToScheme(scheme)
}

func main() {
Expand Down Expand Up @@ -588,6 +591,11 @@ func main() {
klog.Errorf("Unable to start the ipReconciler", err)
os.Exit(1)
}
cfgr := configurationcontroller.NewConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("configuration-controller"))
if err = cfgr.SetupWithManager(mgr); err != nil {
klog.Errorf("unable to create controller ConfigurationReconciler: %s", err)
os.Exit(1)
}
}

klog.Info("starting manager as controller manager")
Expand Down
3 changes: 3 additions & 0 deletions deployments/liqo/charts/liqo-crds/crds/ipam.liqo.io_ips.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ spec:
properties:
ip:
description: IP is the local 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
serviceTemplate:
description: ServiceTemplate contains the template to create the associated
Expand Down Expand Up @@ -424,6 +425,8 @@ spec:
properties:
ipMappings:
additionalProperties:
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
description: IPMappings contains the mapping of the local IP for each
remote cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
properties:
cidr:
description: CIDR is the desired CIDR for the remote 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-2])$
type: string
required:
- cidr
Expand All @@ -57,6 +58,7 @@ spec:
properties:
cidr:
description: CIDR is the remapped CIDR for the remote 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-2])$
type: string
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-2])$
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-2])$
type: string
type: object
type: object
Expand All @@ -61,9 +63,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-2])$
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-2])$
type: string
type: object
type: object
Expand All @@ -80,9 +84,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-2])$
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-2])$
type: string
type: object
type: object
Expand Down
20 changes: 20 additions & 0 deletions deployments/liqo/files/liqo-controller-manager-ClusterRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,26 @@ rules:
- get
- update
- watch
- apiGroups:
- networking.liqo.io
resources:
- configurations
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- networking.liqo.io
resources:
- configurations/status
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- offloading.liqo.io
resources:
Expand Down
Loading

0 comments on commit 0b99353

Please sign in to comment.