Skip to content

Commit

Permalink
Merge pull request #1780 from bowei/configmap-watch
Browse files Browse the repository at this point in the history
ConfigMap informer should only watch --asm-configmap-based-config-nam…
  • Loading branch information
k8s-ci-robot authored Aug 12, 2022
2 parents c926ab5 + 1679d2f commit 099c1e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/cmconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ func (c *ConfigMapConfigController) DisableASM() {

// SetASMReadyTrue update the ASMReady to True.
func (c *ConfigMapConfigController) SetASMReadyTrue() {
klog.V(0).Info("SetASMReadyTrue")
c.updateASMReady(trueValue)
}

// SetASMReadyFalse update the ASMReady to False.
func (c *ConfigMapConfigController) SetASMReadyFalse() {
klog.V(0).Info("SetASMReadyFalse")
c.updateASMReady(falseValue)
}

Expand Down Expand Up @@ -125,10 +127,15 @@ func (c *ConfigMapConfigController) RegisterInformer(configMapInformer cache.Sha
}

func (c *ConfigMapConfigController) processItem(obj interface{}, cancel func()) {
klog.V(4).Infof("ConfigMapConfigController.processItem()")

configMap, ok := obj.(*v1.ConfigMap)
if !ok {
klog.Errorf("ConfigMapConfigController: failed to convert informer object to ConfigMap.")
}

klog.V(3).Infof("ConfigMapConfigController.processItem '%s.%s'", configMap.Namespace, configMap.Name)

if configMap.Namespace != c.configMapNamespace || configMap.Name != c.configMapName {
return
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
informers "k8s.io/client-go/informers"
informerv1 "k8s.io/client-go/informers/core/v1"
discoveryinformer "k8s.io/client-go/informers/discovery/v1"
informernetworking "k8s.io/client-go/informers/networking/v1"
Expand Down Expand Up @@ -224,8 +225,10 @@ func (ctx *ControllerContext) Init() {
klog.V(2).Infof("Controller Context initializing with %+v", ctx.ControllerContextConfig)
// Initialize controller context internals based on ASMConfigMap
if ctx.EnableASMConfigMap {
configMapInformer := informerv1.NewConfigMapInformer(ctx.KubeClient, ctx.Namespace, ctx.ResyncPeriod, utils.NewNamespaceIndexer())
ctx.ConfigMapInformer = configMapInformer
klog.Infof("ASMConfigMap is enabled")

informerFactory := informers.NewSharedInformerFactoryWithOptions(ctx.KubeClient, ctx.ResyncPeriod, informers.WithNamespace(ctx.ASMConfigMapNamespace))
ctx.ConfigMapInformer = informerFactory.Core().V1().ConfigMaps().Informer()
ctx.ASMConfigController = cmconfig.NewConfigMapConfigController(ctx.KubeClient, ctx.Recorder(ctx.ASMConfigMapNamespace), ctx.ASMConfigMapNamespace, ctx.ASMConfigMapName)

cmConfig := ctx.ASMConfigController.GetConfig()
Expand All @@ -235,7 +238,6 @@ func (ctx *ControllerContext) Init() {
ctx.ASMConfigController.SetASMReadyFalse()
}
}

}

func (ctx *ControllerContext) initEnableASM() {
Expand All @@ -247,6 +249,8 @@ func (ctx *ControllerContext) initEnableASM() {
destinationRuleCRDName = "destinationrules.networking.istio.io"
)

klog.V(0).Infof("ASM mode is enabled from ConfigMap")

apiextensionClient, err := apiextensionsclientset.NewForConfig(ctx.KubeConfig)
if err != nil {
msg := fmt.Sprintf("Failed to create ApiextensionClient for DestinationRule, disabling ASM Mode, error: %s", err)
Expand Down

0 comments on commit 099c1e3

Please sign in to comment.