istio.io/istio@v0.0.0-20240520182934-d79c90f27776/cni/pkg/config/config.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package config
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  )
    21  
    22  type Config struct {
    23  	InstallConfig InstallConfig
    24  	RepairConfig  RepairConfig
    25  }
    26  
    27  // InstallConfig struct defines the Istio CNI installation options
    28  type InstallConfig struct {
    29  	// Location of the CNI config files in the host's filesystem
    30  	CNINetDir string
    31  	// Location of the CNI config files in the container's filesystem (mount location of the CNINetDir)
    32  	MountedCNINetDir string
    33  	// Name of the CNI config file
    34  	CNIConfName string
    35  	// Whether to install CNI plugin as a chained or standalone
    36  	ChainedCNIPlugin bool
    37  
    38  	// Logging level
    39  	LogLevel string
    40  	// Name of the kubeconfig file used by the CNI plugin
    41  	KubeconfigFilename string
    42  	// The file mode to set when creating the kubeconfig file
    43  	KubeconfigMode int
    44  	// CA file for kubeconfig
    45  	KubeCAFile string
    46  	// Whether to use insecure TLS in the kubeconfig file
    47  	SkipTLSVerify bool
    48  
    49  	// Comma-separated list of K8S namespaces that CNI should ignore
    50  	ExcludeNamespaces string
    51  
    52  	// KUBERNETES_SERVICE_PROTOCOL
    53  	K8sServiceProtocol string
    54  	// KUBERNETES_SERVICE_HOST
    55  	K8sServiceHost string
    56  	// KUBERNETES_SERVICE_PORT
    57  	K8sServicePort string
    58  	// KUBERNETES_NODE_NAME
    59  	K8sNodeName string
    60  	// Path where service account secrets live, e.g. "/var/run/secrets/kubernetes.io/serviceaccount"
    61  	// Tests may override.
    62  	K8sServiceAccountPath string
    63  
    64  	// Directory from where the CNI binaries should be copied
    65  	CNIBinSourceDir string
    66  	// Directories into which to copy the CNI binaries
    67  	CNIBinTargetDirs []string
    68  
    69  	// The HTTP port for monitoring
    70  	MonitoringPort int
    71  
    72  	// The UDS server address that CNI plugin will send log to.
    73  	LogUDSAddress string
    74  
    75  	// The watch server socket address that CNI plugin will forward CNI events to.
    76  	CNIEventAddress string
    77  
    78  	// The ztunnel server socket address that the ztunnel will connect to.
    79  	ZtunnelUDSAddress string
    80  
    81  	// Whether ambient is enabled
    82  	AmbientEnabled bool
    83  
    84  	// Whether ambient DNS capture is enabled
    85  	AmbientDNSCapture bool
    86  
    87  	// Whether ipv6 is enabled for ambient capture
    88  	AmbientIPv6 bool
    89  }
    90  
    91  // RepairConfig struct defines the Istio CNI race repair configuration
    92  type RepairConfig struct {
    93  	// Whether to enable CNI race repair
    94  	Enabled bool
    95  
    96  	// The node name that the CNI DaemonSet runs on
    97  	NodeName string
    98  
    99  	// Key and value for broken pod label
   100  	LabelKey   string
   101  	LabelValue string
   102  
   103  	// Whether to fix race condition by repairing them
   104  	RepairPods bool
   105  
   106  	// Whether to fix race condition by delete broken pods
   107  	DeletePods bool
   108  
   109  	// Whether to label broken pods
   110  	LabelPods bool
   111  
   112  	// Filters for race repair, including name of sidecar annotation, name of init container,
   113  	// init container termination message and exit code.
   114  	SidecarAnnotation  string
   115  	InitContainerName  string
   116  	InitTerminationMsg string
   117  	InitExitCode       int
   118  
   119  	// Label and field selectors to select pods managed by race repair.
   120  	LabelSelectors string
   121  	FieldSelectors string
   122  }
   123  
   124  func (c InstallConfig) String() string {
   125  	var b strings.Builder
   126  	b.WriteString("CNINetDir: " + c.CNINetDir + "\n")
   127  	b.WriteString("MountedCNINetDir: " + c.MountedCNINetDir + "\n")
   128  	b.WriteString("CNIConfName: " + c.CNIConfName + "\n")
   129  	b.WriteString("ChainedCNIPlugin: " + fmt.Sprint(c.ChainedCNIPlugin) + "\n")
   130  
   131  	b.WriteString("LogLevel: " + c.LogLevel + "\n")
   132  	b.WriteString("KubeconfigFilename: " + c.KubeconfigFilename + "\n")
   133  	b.WriteString("KubeconfigMode: " + fmt.Sprintf("%#o", c.KubeconfigMode) + "\n")
   134  	b.WriteString("KubeCAFile: " + c.KubeCAFile + "\n")
   135  	b.WriteString("SkipTLSVerify: " + fmt.Sprint(c.SkipTLSVerify) + "\n")
   136  
   137  	b.WriteString("ExcludeNamespaces: " + fmt.Sprint(c.ExcludeNamespaces) + "\n")
   138  	b.WriteString("K8sServiceProtocol: " + c.K8sServiceProtocol + "\n")
   139  	b.WriteString("K8sServiceHost: " + c.K8sServiceHost + "\n")
   140  	b.WriteString("K8sServicePort: " + fmt.Sprint(c.K8sServicePort) + "\n")
   141  	b.WriteString("K8sNodeName: " + c.K8sNodeName + "\n")
   142  
   143  	b.WriteString("CNIBinSourceDir: " + c.CNIBinSourceDir + "\n")
   144  	b.WriteString("CNIBinTargetDirs: " + strings.Join(c.CNIBinTargetDirs, ",") + "\n")
   145  
   146  	b.WriteString("MonitoringPort: " + fmt.Sprint(c.MonitoringPort) + "\n")
   147  	b.WriteString("LogUDSAddress: " + fmt.Sprint(c.LogUDSAddress) + "\n")
   148  	b.WriteString("CNIEventAddress: " + fmt.Sprint(c.CNIEventAddress) + "\n")
   149  	b.WriteString("ZtunnelUDSAddress: " + fmt.Sprint(c.ZtunnelUDSAddress) + "\n")
   150  
   151  	b.WriteString("AmbientEnabled: " + fmt.Sprint(c.AmbientEnabled) + "\n")
   152  	b.WriteString("AmbientDNSCapture: " + fmt.Sprint(c.AmbientDNSCapture) + "\n")
   153  	b.WriteString("AmbientIPv6: " + fmt.Sprint(c.AmbientIPv6) + "\n")
   154  
   155  	return b.String()
   156  }
   157  
   158  func (c RepairConfig) String() string {
   159  	var b strings.Builder
   160  	b.WriteString("Enabled: " + fmt.Sprint(c.Enabled) + "\n")
   161  	b.WriteString("NodeName: " + c.NodeName + "\n")
   162  	b.WriteString("LabelKey: " + c.LabelKey + "\n")
   163  	b.WriteString("LabelValue: " + c.LabelValue + "\n")
   164  	b.WriteString("DeletePods: " + fmt.Sprint(c.DeletePods) + "\n")
   165  	b.WriteString("LabelPods: " + fmt.Sprint(c.LabelPods) + "\n")
   166  	b.WriteString("SidecarAnnotation: " + c.SidecarAnnotation + "\n")
   167  	b.WriteString("InitContainerName: " + c.InitContainerName + "\n")
   168  	b.WriteString("InitTerminationMsg: " + c.InitTerminationMsg + "\n")
   169  	b.WriteString("InitExitCode: " + fmt.Sprint(c.InitExitCode) + "\n")
   170  	b.WriteString("LabelSelectors: " + c.LabelSelectors + "\n")
   171  	b.WriteString("FieldSelectors: " + c.FieldSelectors + "\n")
   172  	return b.String()
   173  }