mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-29 06:06:03 +00:00
Merge pull request #46197 from xiangpengzhao/fix-allocate-clusterip
Automatic merge from submit-queue (batch tested with PRs 47850, 47835, 46197, 47250, 48284) Allocate clusterIP when change service type from ExternalName to ClusterIP **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #35354 #46190 **Special notes for your reviewer**: /cc @smarterclayton @thockin **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -35,6 +35,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
"k8s.io/kubernetes/pkg/client/retry"
|
||||
@@ -177,6 +178,31 @@ func (j *ServiceTestJig) CreateUDPServiceOrFail(namespace string, tweak func(svc
|
||||
return result
|
||||
}
|
||||
|
||||
// CreateExternalNameServiceOrFail creates a new ExternalName type Service based on the jig's defaults.
|
||||
// Callers can provide a function to tweak the Service object before it is created.
|
||||
func (j *ServiceTestJig) CreateExternalNameServiceOrFail(namespace string, tweak func(svc *v1.Service)) *v1.Service {
|
||||
svc := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: j.Name,
|
||||
Labels: j.Labels,
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
Selector: j.Labels,
|
||||
ExternalName: "foo.example.com",
|
||||
Type: v1.ServiceTypeExternalName,
|
||||
},
|
||||
}
|
||||
if tweak != nil {
|
||||
tweak(svc)
|
||||
}
|
||||
result, err := j.Client.Core().Services(namespace).Create(svc)
|
||||
if err != nil {
|
||||
Failf("Failed to create ExternalName Service %q: %v", svc.Name, err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (j *ServiceTestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration) {
|
||||
ingressIP := ""
|
||||
svc := j.UpdateServiceOrFail(namespace, name, func(s *v1.Service) {
|
||||
@@ -373,8 +399,22 @@ func (j *ServiceTestJig) SanityCheckService(svc *v1.Service, svcType v1.ServiceT
|
||||
if svc.Spec.Type != svcType {
|
||||
Failf("unexpected Spec.Type (%s) for service, expected %s", svc.Spec.Type, svcType)
|
||||
}
|
||||
|
||||
if svcType != v1.ServiceTypeExternalName {
|
||||
if svc.Spec.ExternalName != "" {
|
||||
Failf("unexpected Spec.ExternalName (%s) for service, expected empty", svc.Spec.ExternalName)
|
||||
}
|
||||
if svc.Spec.ClusterIP != api.ClusterIPNone && svc.Spec.ClusterIP == "" {
|
||||
Failf("didn't get ClusterIP for non-ExternamName service")
|
||||
}
|
||||
} else {
|
||||
if svc.Spec.ClusterIP != "" {
|
||||
Failf("unexpected Spec.ClusterIP (%s) for ExternamName service, expected empty", svc.Spec.ClusterIP)
|
||||
}
|
||||
}
|
||||
|
||||
expectNodePorts := false
|
||||
if svcType != v1.ServiceTypeClusterIP {
|
||||
if svcType != v1.ServiceTypeClusterIP && svcType != v1.ServiceTypeExternalName {
|
||||
expectNodePorts = true
|
||||
}
|
||||
for i, port := range svc.Spec.Ports {
|
||||
|
Reference in New Issue
Block a user