-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controller implementation for CIDRPool
Signed-off-by: Yury Kulazhenkov <ykulazhenkov@nvidia.com>
- Loading branch information
1 parent
04161b8
commit f8465ca
Showing
9 changed files
with
808 additions
and
227 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2024, NVIDIA CORPORATION & AFFILIATES | ||
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 ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
logPkg "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
var cidrPoolLogger = logPkg.Log.WithName("CIDRPool-validator") | ||
|
||
// SetupWebhookWithManager registers webhook handler in the manager | ||
func (r *CIDRPool) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(r). | ||
Complete() | ||
} | ||
|
||
var _ webhook.Validator = &IPPool{} | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type | ||
func (r *CIDRPool) ValidateCreate() (admission.Warnings, error) { | ||
cidrPoolLogger.V(1).Info("validate create", "name", r.Name) | ||
return r.validate() | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type | ||
func (r *CIDRPool) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { | ||
cidrPoolLogger.V(1).Info("validate update", "name", r.Name) | ||
return r.validate() | ||
} | ||
|
||
func (r *CIDRPool) validate() (admission.Warnings, error) { | ||
errList := r.Validate() | ||
if len(errList) == 0 { | ||
cidrPoolLogger.V(1).Info("validation succeed") | ||
return nil, nil | ||
} | ||
err := errList.ToAggregate() | ||
cidrPoolLogger.V(1).Info("validation failed", "reason", err.Error()) | ||
return nil, err | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type | ||
func (r *CIDRPool) ValidateDelete() (admission.Warnings, error) { | ||
return nil, nil | ||
} |
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 |
---|---|---|
|
@@ -31,7 +31,6 @@ import ( | |
|
||
const ( | ||
TestNamespace = "test-ns" | ||
TestConfigMapName = "test-config" | ||
) | ||
|
||
var ( | ||
|
Oops, something went wrong.