-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support service webhook to add service topology annotation for …
…vip-loadbalance Signed-off-by: wangxye <[email protected]>
- Loading branch information
Showing
6 changed files
with
276 additions
and
227 deletions.
There are no files selected for viewing
61 changes: 0 additions & 61 deletions
61
pkg/yurtmanager/webhook/poolservice/v1alpha1/poolservice_default.go
This file was deleted.
Oops, something went wrong.
144 changes: 0 additions & 144 deletions
144
pkg/yurtmanager/webhook/poolservice/v1alpha1/poolservice_default_test.go
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2024 The OpenYurt 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 corev1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
viplb "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/loadbalancerset/viploadbalancer" | ||
) | ||
|
||
// Default satisfies the defaulting webhook interface. | ||
func (webhook *ServiceHandler) Default(ctx context.Context, obj runtime.Object) error { | ||
svc, ok := obj.(*corev1.Service) | ||
if !ok { | ||
return apierrors.NewBadRequest(fmt.Sprintf("expected a Service but got a %T", obj)) | ||
} | ||
|
||
if svc.Spec.Type == corev1.ServiceTypeLoadBalancer { | ||
if svc.Spec.LoadBalancerClass != nil && *svc.Spec.LoadBalancerClass == viplb.VipLoadBalancerClass { | ||
if svc.Annotations == nil { | ||
svc.Annotations = make(map[string]string) | ||
} | ||
|
||
if _, ok := svc.Annotations[viplb.AnnotationServiceTopologyKey]; !ok { | ||
svc.Annotations[viplb.AnnotationServiceTopologyKey] = viplb.AnnotationServiceTopologyValueNodePool | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.