@@ -56,6 +56,8 @@ const (
5656 // Operator components
5757 IstioOperatorComponentName ComponentName = "IstioOperator"
5858 IstioOperatorCustomResourceName ComponentName = "IstioOperatorCustomResource"
59+
60+
5961)
6062
6163var (
7274 CNIComponentName ,
7375 }
7476 allComponentNamesMap = make (map [ComponentName ]bool )
77+ // TODO: merge this with the componentMaps defined in translateConfig
78+ // ComponentNameToHelmComponentPath defines mapping from component name to helm component root path.
79+ ComponentNameToHelmComponentPath = map [ComponentName ]string {
80+ PilotComponentName : "pilot" ,
81+ GalleyComponentName : "galley" ,
82+ SidecarInjectorComponentName : "sidecarInjectorWebhook" ,
83+ PolicyComponentName : "mixer.policy" ,
84+ TelemetryComponentName : "mixer.telemetry" ,
85+ CitadelComponentName : "security" ,
86+ CertManagerComponentName : "certmanager" ,
87+ NodeAgentComponentName : "nodeagent" ,
88+ IngressComponentName : "gateways.istio-ingressgateway" ,
89+ EgressComponentName : "gateways.istio-egressgateway" ,
90+ CNIComponentName : "cni" ,
91+ }
7592)
7693
7794func init () {
@@ -100,7 +117,14 @@ func (cn ComponentName) IsAddon() bool {
100117
101118// IsComponentEnabledInSpec reports whether the given component is enabled in the given spec.
102119// IsComponentEnabledInSpec assumes that controlPlaneSpec has been validated.
120+ // TODO: remove extra validations when comfort level is high enough.
103121func IsComponentEnabledInSpec (componentName ComponentName , controlPlaneSpec * v1alpha1.IstioOperatorSpec ) (bool , error ) {
122+ // if component enablement path is defined and found in Values part, return it first, otherwise check from ISCP.
123+ valuePath := ComponentNameToHelmComponentPath [componentName ]
124+ enabled , pathExist , err := IsComponentEnabledFromValue (valuePath , controlPlaneSpec .Values )
125+ if err == nil && pathExist {
126+ return enabled , nil
127+ }
104128 if componentName == IngressComponentName {
105129 return len (controlPlaneSpec .Components .IngressGateways ) != 0 , nil
106130 }
@@ -128,25 +152,28 @@ func IsComponentEnabledInSpec(componentName ComponentName, controlPlaneSpec *v1a
128152
129153// IsComponentEnabledFromValue get whether component is enabled in helm value.yaml tree.
130154// valuePath points to component path in the values tree.
131- func IsComponentEnabledFromValue (valuePath string , valueSpec map [string ]interface {}) (bool , error ) {
155+ func IsComponentEnabledFromValue (valuePath string , valueSpec map [string ]interface {}) (enabled bool , pathExist bool , err error ) {
132156 enabledPath := valuePath + ".enabled"
133157 enableNodeI , found , err := tpath .GetFromTreePath (valueSpec , util .ToYAMLPath (enabledPath ))
134158 if err != nil {
135- return false , fmt .Errorf ("error finding component enablement path: %s in helm value.yaml tree" , enabledPath )
159+ return false , false , fmt .Errorf ("error finding component enablement path: %s in helm value.yaml tree" , enabledPath )
136160 }
137161 if ! found {
138162 // Some components do not specify enablement should be treated as enabled if the root node in the component subtree exists.
139163 _ , found , err := tpath .GetFromTreePath (valueSpec , util .ToYAMLPath (valuePath ))
140- if found && err = = nil {
141- return true , nil
164+ if err ! = nil {
165+ return false , false , err
142166 }
143- return false , nil
167+ if found {
168+ return true , true , nil
169+ }
170+ return false , false , nil
144171 }
145172 enableNode , ok := enableNodeI .(bool )
146173 if ! ok {
147- return false , fmt .Errorf ("node at valuePath %s has bad type %T, expect bool" , enabledPath , enableNodeI )
174+ return false , true , fmt .Errorf ("node at valuePath %s has bad type %T, expect bool" , enabledPath , enableNodeI )
148175 }
149- return enableNode , nil
176+ return enableNode , true , nil
150177}
151178
152179// NamespaceFromValue gets the namespace value in helm value.yaml tree.
0 commit comments