forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#1 from XiShanYongYe-Chang/dev-cz
Add resource routing logic to fleet-apiserver
- Loading branch information
Showing
41 changed files
with
2,017 additions
and
64 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
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
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,75 @@ | ||
package storage | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" | ||
"k8s.io/kubernetes/pkg/apis/networking" | ||
) | ||
|
||
func fleetDecorator(obj runtime.Object) { | ||
switch obj.(type) { | ||
case *networking.Ingress: | ||
ing := obj.(*networking.Ingress) | ||
setClusterNameSuffix(ing) | ||
case *networking.IngressList: | ||
items := obj.(*networking.IngressList).Items | ||
for i := range items { | ||
setClusterNameSuffix(&items[i]) | ||
} | ||
default: | ||
} | ||
} | ||
|
||
func setClusterNameSuffix(ing *networking.Ingress) { | ||
if ing == nil || ing.Name == "" { | ||
return | ||
} | ||
|
||
_, clusterName := genericregistry.ParseNameFromResourceName(ing.Name, false) | ||
if clusterName == genericregistry.KarmadaCluster { | ||
return | ||
} | ||
|
||
setSuffixForIngressClassName(ing.Spec.IngressClassName, clusterName) | ||
setSuffixForBackend(ing.Spec.DefaultBackend, clusterName) | ||
setSuffixForRules(ing.Spec.Rules, clusterName) | ||
setSuffixForTLSConfigurations(ing.Spec.TLS, clusterName) | ||
} | ||
|
||
func setSuffixForIngressClassName(ingClass *string, clusterName string) { | ||
if ingClass == nil { | ||
return | ||
} | ||
*ingClass += ".clusterspace." + clusterName | ||
} | ||
|
||
func setSuffixForRules(rules []networking.IngressRule, clusterName string) { | ||
for i := range rules { | ||
rule := &rules[i] | ||
if rule.HTTP == nil { | ||
continue | ||
} | ||
paths := rule.HTTP.Paths | ||
for j := range paths { | ||
setSuffixForBackend(&paths[j].Backend, clusterName) | ||
} | ||
} | ||
} | ||
|
||
func setSuffixForBackend(backend *networking.IngressBackend, clusterName string) { | ||
if backend == nil { | ||
return | ||
} | ||
if svc := backend.Service; svc != nil { | ||
svc.Name += ".clusterspace." + clusterName | ||
} | ||
if resource := backend.Resource; resource != nil { | ||
resource.Name += ".clusterspace." + clusterName | ||
} | ||
} | ||
|
||
func setSuffixForTLSConfigurations(tlsConfigs []networking.IngressTLS, clusterName string) { | ||
for i := range tlsConfigs { | ||
tlsConfigs[i].SecretName += ".clusterspace." + clusterName | ||
} | ||
} |
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
Oops, something went wrong.