-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CSM NEG support. #827
Add CSM NEG support. #827
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package annotations | ||
|
||
import "encoding/json" | ||
|
||
//PortSubsetNegMap is the mapping between subset to NEG name. | ||
type PortSubsetNegMap map[string]map[string]string | ||
|
||
// DestinationRuleNEGStatus holds the NEGs Zones info. | ||
// NetworkEndpointGroups(PortSubsetNegMap) is the mapping between subset to NEG name. | ||
// Structure: | ||
// { | ||
// "subsetv1": { | ||
// "9080": "somehash-default-reviews-v1-9080", | ||
// } | ||
// "v2": { | ||
// "9080": "somehash-default-reviews-v2-9080", | ||
// } | ||
// } | ||
type DestinationRuleNEGStatus struct { | ||
NetworkEndpointGroups PortSubsetNegMap `json:"network_endpoint_groups,omitempty"` | ||
// Zones is a list of zones where the NEGs exist. | ||
Zones []string `json:"zones,omitempty"` | ||
} | ||
|
||
// NewDestinationRuleNegStatus generates a NegStatus denoting the current NEGs | ||
// associated with the given PortSubsetNegMap. | ||
func NewDestinationRuleNegStatus(zones []string, portSubsetToNegs PortSubsetNegMap) DestinationRuleNEGStatus { | ||
res := DestinationRuleNEGStatus{} | ||
res.Zones = zones | ||
res.NetworkEndpointGroups = portSubsetToNegs | ||
return res | ||
} | ||
|
||
// Marshal returns the DestinationRuleNEGStatus in json string. | ||
func (ns DestinationRuleNEGStatus) Marshal() (string, error) { | ||
ret := "" | ||
bytes, err := json.Marshal(ns) | ||
if err != nil { | ||
return ret, err | ||
} | ||
return string(bytes), err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ import ( | |
"time" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/dynamic/dynamicinformer" | ||
informerv1 "k8s.io/client-go/informers/core/v1" | ||
informerv1beta1 "k8s.io/client-go/informers/networking/v1beta1" | ||
"k8s.io/client-go/kubernetes" | ||
|
@@ -42,21 +45,23 @@ const ( | |
|
||
// ControllerContext holds the state needed for the execution of the controller. | ||
type ControllerContext struct { | ||
KubeClient kubernetes.Interface | ||
KubeClient kubernetes.Interface | ||
DestinationRuleClient dynamic.NamespaceableResourceInterface | ||
|
||
Cloud *gce.Cloud | ||
|
||
ClusterNamer *utils.Namer | ||
|
||
ControllerContextConfig | ||
|
||
IngressInformer cache.SharedIndexInformer | ||
ServiceInformer cache.SharedIndexInformer | ||
BackendConfigInformer cache.SharedIndexInformer | ||
FrontendConfigInformer cache.SharedIndexInformer | ||
PodInformer cache.SharedIndexInformer | ||
NodeInformer cache.SharedIndexInformer | ||
EndpointInformer cache.SharedIndexInformer | ||
IngressInformer cache.SharedIndexInformer | ||
ServiceInformer cache.SharedIndexInformer | ||
BackendConfigInformer cache.SharedIndexInformer | ||
FrontendConfigInformer cache.SharedIndexInformer | ||
PodInformer cache.SharedIndexInformer | ||
NodeInformer cache.SharedIndexInformer | ||
EndpointInformer cache.SharedIndexInformer | ||
DestinationRuleInformer cache.SharedIndexInformer | ||
|
||
healthChecks map[string]func() error | ||
|
||
|
@@ -75,11 +80,13 @@ type ControllerContextConfig struct { | |
HealthCheckPath string | ||
DefaultBackendHealthCheckPath string | ||
FrontendConfigEnabled bool | ||
EnableCSM bool | ||
} | ||
|
||
// NewControllerContext returns a new shared set of informers. | ||
func NewControllerContext( | ||
kubeClient kubernetes.Interface, | ||
dynamicClient dynamic.Interface, | ||
backendConfigClient backendconfigclient.Interface, | ||
frontendConfigClient frontendconfigclient.Interface, | ||
cloud *gce.Cloud, | ||
|
@@ -101,6 +108,16 @@ func NewControllerContext( | |
healthChecks: make(map[string]func() error), | ||
} | ||
|
||
if config.EnableCSM && dynamicClient != nil { | ||
klog.Warning("The DestinationRule group version is v1alpha3 in group networking.istio.io. Need to update as istio API graduates.") | ||
destrinationGVR := schema.GroupVersionResource{Group: "networking.istio.io", Version: "v1alpha3", Resource: "destinationrules"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a WARNING here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks |
||
drDynamicInformer := dynamicinformer.NewFilteredDynamicInformer(dynamicClient, destrinationGVR, config.Namespace, config.ResyncPeriod, | ||
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, | ||
nil) | ||
context.DestinationRuleInformer = drDynamicInformer.Informer() | ||
context.DestinationRuleClient = dynamicClient.Resource(destrinationGVR) | ||
} | ||
|
||
if config.FrontendConfigEnabled { | ||
context.FrontendConfigInformer = informerfrontendconfig.NewFrontendConfigInformer(frontendConfigClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()) | ||
} | ||
|
@@ -123,6 +140,10 @@ func (ctx *ControllerContext) HasSynced() bool { | |
funcs = append(funcs, ctx.FrontendConfigInformer.HasSynced) | ||
} | ||
|
||
if ctx.DestinationRuleInformer != nil { | ||
funcs = append(funcs, ctx.DestinationRuleInformer.HasSynced) | ||
} | ||
|
||
for _, f := range funcs { | ||
if !f() { | ||
return false | ||
|
@@ -187,6 +208,9 @@ func (ctx *ControllerContext) Start(stopCh chan struct{}) { | |
if ctx.FrontendConfigInformer != nil { | ||
go ctx.FrontendConfigInformer.Run(stopCh) | ||
} | ||
if ctx.DestinationRuleInformer != nil { | ||
go ctx.DestinationRuleInformer.Run(stopCh) | ||
} | ||
} | ||
|
||
// Ingresses returns the store of Ingresses. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean move the comment from above to here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done