github.com/banzaicloud/istio-operator/pkg/apis@v0.10.8/istio/v1beta1/meshgateway_defaults.go (about)

     1  /*
     2  Copyright 2019 Banzai Cloud.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	apiv1 "k8s.io/api/core/v1"
    21  
    22  	"github.com/banzaicloud/operator-tools/pkg/utils"
    23  )
    24  
    25  func (c *MeshGatewayConfiguration) SetDefaults() {
    26  	if c.ReplicaCount == nil {
    27  		c.ReplicaCount = utils.IntPointer(defaultReplicaCount)
    28  	}
    29  	if c.MinReplicas == nil {
    30  		c.MinReplicas = utils.IntPointer(defaultReplicaCount)
    31  	}
    32  	if c.MaxReplicas == nil {
    33  		c.MaxReplicas = utils.IntPointer(defaultReplicaCount)
    34  	}
    35  	if c.Resources == nil {
    36  		c.Resources = defaultProxyResources
    37  	}
    38  	if c.SDS.Enabled == nil {
    39  		c.SDS.Enabled = utils.BoolPointer(false)
    40  	}
    41  	if c.SDS.Image == "" {
    42  		c.SDS.Image = defaultNodeAgentImage
    43  	}
    44  	if c.RunAsRoot == nil {
    45  		c.RunAsRoot = utils.BoolPointer(false)
    46  	}
    47  	if c.SecurityContext == nil {
    48  		if utils.PointerToBool(c.RunAsRoot) {
    49  			c.SecurityContext = &apiv1.SecurityContext{
    50  				RunAsUser:    utils.IntPointer64(0),
    51  				RunAsGroup:   utils.IntPointer64(0),
    52  				RunAsNonRoot: utils.BoolPointer(false),
    53  			}
    54  		} else {
    55  			c.SecurityContext = defaultSecurityContext
    56  		}
    57  	}
    58  }
    59  
    60  func (gw *MeshGateway) SetDefaults() {
    61  	gw.Spec.MeshGatewayConfiguration.SetDefaults()
    62  
    63  	if gw.Spec.Type == GatewayTypeIngress && gw.Spec.ServiceType == "" {
    64  		gw.Spec.ServiceType = defaultIngressGatewayServiceType
    65  	}
    66  	if gw.Spec.Type == GatewayTypeEgress && gw.Spec.ServiceType == "" {
    67  		gw.Spec.ServiceType = defaultEgressGatewayServiceType
    68  	}
    69  	// always turn off SDS for egress
    70  	if gw.Spec.Type == GatewayTypeEgress {
    71  		gw.Spec.SDS.Enabled = utils.BoolPointer(false)
    72  	}
    73  	if gw.Spec.Ports == nil {
    74  		gw.Spec.Ports = make([]ServicePort, 0)
    75  	}
    76  
    77  	gw.SetDefaultLabels()
    78  }
    79  
    80  func (gw *MeshGateway) SetDefaultLabels() {
    81  	gw.Spec.Labels = MergeStringMaps(gw.GetDefaultLabels(), gw.Spec.Labels)
    82  }
    83  
    84  func (gw *MeshGateway) GetDefaultLabels() map[string]string {
    85  	return map[string]string{
    86  		"gateway-name": gw.Name,
    87  		"gateway-type": string(gw.Spec.Type),
    88  	}
    89  }