-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
336 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
116 changes: 116 additions & 0 deletions
116
pkg/liqonet/configuration-controller/configuration-controller.go
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,116 @@ | ||
// 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" | ||
|
||
ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" | ||
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) | ||
} | ||
|
||
requeue, err := r.RemapConfiguration(ctx, configuration) | ||
if requeue || err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
return ctrl.Result{}, r.UpdateConfigurationStatus(ctx, configuration) | ||
} | ||
|
||
// RemapConfiguration remap the configuration using ipamv1alpha1.Network. | ||
func (r *ConfigurationReconciler) RemapConfiguration(ctx context.Context, cfg *networkingv1alpha1.Configuration) (requeue bool, err error) { | ||
var cidrRemapped networkingv1alpha1.CIDR | ||
for _, cidrType := range LabelCIDRTypeValues { | ||
switch cidrType { | ||
case LabelCIDRTypePod: | ||
cidrRemapped = cfg.Status.Remote.CIDR.Pod | ||
case LabelCIDRTypeExternal: | ||
cidrRemapped = cfg.Status.Remote.CIDR.External | ||
} | ||
if cidrRemapped != "" { | ||
continue | ||
} | ||
network, err := CreateOrGetNetwork(ctx, r.Client, r.Scheme, cfg, cidrType) | ||
if err != nil { | ||
return true, fmt.Errorf(" %w --> Unable to create or get the network '%s'", err, network.Name) | ||
} | ||
if network.Status.CIDR == "" { | ||
return true, nil | ||
} | ||
var cidrNew, cidrOld networkingv1alpha1.CIDR | ||
cidrNew = network.Status.CIDR | ||
switch cidrType { | ||
case LabelCIDRTypePod: | ||
cidrOld = cfg.Status.Remote.CIDR.Pod | ||
cfg.Status.Remote.CIDR.Pod = network.Status.CIDR | ||
case LabelCIDRTypeExternal: | ||
cidrOld = cfg.Status.Remote.CIDR.External | ||
cfg.Status.Remote.CIDR.External = network.Status.CIDR | ||
} | ||
klog.Infof("Configuration %s/%s %s CIDR: %s -> %s", cfg.Name, cfg.Namespace, cidrType, cidrOld, cidrNew) | ||
} | ||
return false, nil | ||
} | ||
|
||
func (r *ConfigurationReconciler) UpdateConfigurationStatus(ctx context.Context, cfg *networkingv1alpha1.Configuration) error { | ||
if err := r.Status().Update(ctx, cfg); err != nil { | ||
return fmt.Errorf(" %w --> Unable to update the configuration '%s'", err, cfg.Name) | ||
} | ||
return nil | ||
} | ||
|
||
// SetupWithManager register the ConfigurationReconciler to the manager. | ||
func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr).Owns(&ipamv1alpha1.Network{}). | ||
For(&networkingv1alpha1.Configuration{}).Complete(r) | ||
} |
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,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 |
Oops, something went wrong.