github.phpd.cn/cilium/cilium@v1.6.12/test/helpers/cons.go (about) 1 // Copyright 2017-2019 Authors of Cilium 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 helpers 16 17 import ( 18 "bytes" 19 "fmt" 20 "os" 21 "path" 22 "time" 23 24 k8sConst "github.com/cilium/cilium/pkg/k8s/apis/cilium.io" 25 "github.com/cilium/cilium/pkg/versioncheck" 26 "github.com/cilium/cilium/test/ginkgo-ext" 27 ) 28 29 var ( 30 // HelperTimeout is a predefined timeout value for commands. 31 HelperTimeout = 4 * time.Minute 32 33 // ShortCommandTimeout is a timeout for commands which should not take a 34 // long time to execute. 35 ShortCommandTimeout = 10 * time.Second 36 37 // MidCommandTimeout is a timeout for commands which may take a bit longer 38 // than ShortCommandTimeout, but less time than HelperTimeout to execute. 39 MidCommandTimeout = 30 * time.Second 40 41 // CiliumStartTimeout is a predefined timeout value for Cilium startup. 42 CiliumStartTimeout = 100 * time.Second 43 44 // CiliumBasePath is the absolute path to the cilium source repository 45 // in the guest VMs 46 CiliumBasePath = "/home/vagrant/go/src/github.com/cilium/cilium" 47 48 // BasePath is the path in the Vagrant VMs to which the test directory 49 // is mounted 50 BasePath = path.Join(CiliumBasePath, "test") 51 52 // CheckLogs newtes a new buffer where all the warnings and checks that 53 // happens during the test are saved. This buffer will be printed in the 54 // test output inside <checks> labels. 55 CheckLogs = ginkgoext.NewWriter(new(bytes.Buffer)) 56 ) 57 58 const ( 59 60 //CiliumPath is the path where cilium test code is located. 61 CiliumPath = "/src/github.com/cilium/cilium/test" 62 63 // K8sManifestBase tells ginkgo suite where to look for manifests 64 K8sManifestBase = "k8sT/manifests" 65 66 // VM / Test suite constants. 67 K8s = "k8s" 68 K8s1 = "k8s1" 69 K8s1Ip = "192.168.36.11" 70 K8s2 = "k8s2" 71 K8s2Ip = "192.168.36.12" 72 Runtime = "runtime" 73 74 Enabled = "enabled" 75 Disabled = "disabled" 76 Total = "total" 77 Public = "public" 78 Private = "private" 79 Name = "Name" 80 81 // PolicyEnforcement represents the PolicyEnforcement configuration option 82 // for the Cilium agent. 83 PolicyEnforcement = "PolicyEnforcement" 84 85 // PolicyEnforcementDefault represents the default PolicyEnforcement mode 86 // for Cilium. 87 PolicyEnforcementDefault = "default" 88 89 // PolicyEnforcementAlways represents the PolicyEnforcement mode 90 // for Cilium in which traffic is denied by default even when no policy 91 // is imported. 92 PolicyEnforcementAlways = "always" 93 94 // PolicyEnforcementNever represents the PolicyEnforcement mode 95 // for Cilium in which traffic is always allowed even if there is a policy 96 // selecting endpoints. 97 PolicyEnforcementNever = "never" 98 99 // CiliumDockerNetwork is the name of the Docker network which Cilium manages. 100 CiliumDockerNetwork = "cilium-net" 101 102 // HostDockerNetwork is the name of the host network driver. 103 HostDockerNetwork = "host" 104 105 // Names of commonly used containers in tests. 106 Httpd1 = "httpd1" 107 Httpd2 = "httpd2" 108 Httpd3 = "httpd3" 109 App1 = "app1" 110 App2 = "app2" 111 App3 = "app3" 112 Client = "client" 113 Server = "server" 114 Host = "host" 115 // Container lifecycle actions. 116 Create = "create" 117 Delete = "delete" 118 119 // IP Address families. 120 IPv4 = "IPv4" 121 IPv6 = "IPv6" 122 123 // LogPerm is the permission for files that are created by this framework 124 // that contain logs, outputs of Cilium CLI commands, etc. 125 LogPerm = os.FileMode(0666) 126 127 // Configuration options for endpoints. Copied from endpoint/endpoint.go 128 // TODO: these should be converted into types for use in configuration 129 // functions instead of using basic strings. 130 131 OptionConntrackAccounting = "ConntrackAccounting" 132 OptionConntrackLocal = "ConntrackLocal" 133 OptionConntrack = "Conntrack" 134 OptionDebug = "Debug" 135 OptionDropNotify = "DropNotification" 136 OptionTraceNotify = "TraceNotification" 137 OptionNAT46 = "NAT46" 138 OptionIngressPolicy = "IngressPolicy" 139 OptionEgressPolicy = "EgressPolicy" 140 OptionIngress = "ingress" 141 OptionEgress = "egress" 142 OptionNone = "none" 143 OptionDisabled = "Disabled" 144 OptionEnabled = "Enabled" 145 146 StateTerminating = "Terminating" 147 StateRunning = "Running" 148 149 PingCount = 5 150 151 // CurlConnectTimeout is the timeout for the connect() call that curl 152 // invokes 153 CurlConnectTimeout = 5 154 155 // CurlMaxTimeout is the hard timeout. It starts when curl is invoked 156 // and interrupts curl regardless of whether curl is currently 157 // connecting or transferring data. CurlMaxTimeout should be at least 5 158 // seconds longer than CurlConnectTimeout to provide some time to 159 // actually transfer data. 160 CurlMaxTimeout = 8 161 162 DefaultNamespace = "default" 163 KubeSystemNamespace = "kube-system" 164 165 TestResultsPath = "test_results/" 166 RunDir = "/var/run/cilium" 167 LibDir = "/var/lib/cilium" 168 169 DaemonName = "cilium" 170 CiliumBugtool = "cilium-bugtool" 171 CiliumDockerDaemonName = "cilium-docker" 172 AgentDaemon = "cilium-agent" 173 174 GeneratedHTMLManifest = "html.yaml" 175 GeneratedServerManifest = "server.yaml" 176 GeneratedClientManifest = "client.yaml" 177 178 KubectlCreate = ResourceLifeCycleAction("create") 179 KubectlDelete = ResourceLifeCycleAction("delete") 180 KubectlApply = ResourceLifeCycleAction("apply") 181 182 KubectlPolicyNameLabel = k8sConst.PolicyLabelName 183 KubectlPolicyNameSpaceLabel = k8sConst.PolicyLabelNamespace 184 185 CiliumStableVersion = "v1.5" 186 CiliumStableImageVersion = "cilium/cilium:" + CiliumStableVersion 187 CiliumDeveloperImage = "k8s1:5000/cilium/cilium-dev:latest" 188 189 MonitorLogFileName = "monitor.log" 190 microscopeManifest = "microscope.yaml" 191 192 // CiliumTestLog is the filename where the cilium logs that happens during 193 // the test are saved. 194 CiliumTestLog = "cilium-test.log" 195 196 // FakeIPv4WorldAddress is an IP which is used in some datapath tests 197 // for simulating external IPv4 connectivity. 198 FakeIPv4WorldAddress = "192.168.254.254" 199 200 // FakeIPv6WorldAddress is an IP which is used in some datapath tests 201 // for simulating external IPv6 connectivity. 202 FakeIPv6WorldAddress = "fdff::ff" 203 204 // DockerBridgeIP is the IP on the docker0 bridge 205 DockerBridgeIP = "172.17.0.1" 206 207 // Logs messages that should not be in the cilium logs. 208 panicMessage = "panic:" 209 deadLockHeader = "POTENTIAL DEADLOCK:" // from github.com/sasha-s/go-deadlock/deadlock.go:header 210 segmentationFault = "segmentation fault" // from https://github.com/cilium/cilium/issues/3233 211 NACKreceived = "NACK received for version" // from https://github.com/cilium/cilium/issues/4003 212 RunInitFailed = "JoinEP: " // from https://github.com/cilium/cilium/pull/5052 213 sizeMismatch = "size mismatch for BPF map" // from https://github.com/cilium/cilium/issues/7851 214 215 // HelmTemplate is the location of the Helm templates to install Cilium 216 HelmTemplate = "go/src/github.com/cilium/cilium/install/kubernetes/cilium" 217 ) 218 219 // Re-definitions of stable constants in the API. The re-definition is on 220 // purpose to validate these values in the API. They may never change 221 const ( 222 // ReservedIdentityHealth is equivalent to pkg/identity.ReservedIdentityHealth 223 ReservedIdentityHealth = 4 224 ) 225 226 // NightlyStableUpgradesFrom the cilium images to update from in Nightly test. 227 var NightlyStableUpgradesFrom = []string{"v1.3"} 228 229 var ( 230 CiliumV1_5 = versioncheck.MustCompile(">=v1.4.90,<v1.6") 231 CiliumV1_6 = versioncheck.MustCompile(">=v1.5.90,<v1.7") 232 ) 233 234 // CiliumDefaultDSPatch is the default Cilium DaemonSet patch to be used in all tests. 235 const CiliumDefaultDSPatch = "cilium-ds-patch.yaml" 236 237 // CiliumConfigMapPatch is the default Cilium ConfigMap patch to be used in all tests. 238 const CiliumConfigMapPatch = "cilium-cm-patch.yaml" 239 240 // CiliumConfigMapPatchKvstoreAllocator is equivalent to CiliumConfigMapPatch 241 // except it uses the kvstore-based allocator instead of the CRD-based allocator. 242 const CiliumConfigMapPatchKvstoreAllocator = "cilium-cm-kvstore-allocator-patch.yaml" 243 244 // badLogMessages is a map which key is a part of a log message which indicates 245 // a failure if the message does not contain any part from value list. 246 var badLogMessages = map[string][]string{ 247 panicMessage: nil, 248 deadLockHeader: nil, 249 segmentationFault: nil, 250 NACKreceived: nil, 251 RunInitFailed: {"signal: terminated", "signal: killed"}, 252 sizeMismatch: nil, 253 } 254 255 var ciliumCLICommands = map[string]string{ 256 "cilium endpoint list -o json": "endpoint_list.txt", 257 "cilium service list -o json": "service_list.txt", 258 "cilium config": "config.txt", 259 "sudo cilium bpf lb list": "bpf_lb_list.txt", 260 "sudo cilium bpf ct list global": "bpf_ct_list.txt", 261 "sudo cilium bpf tunnel list": "bpf_tunnel_list.txt", 262 "cilium policy get": "policy_get.txt", 263 "cilium status --all-controllers": "status.txt", 264 "cilium kvstore get cilium --recursive": "kvstore_get.txt", 265 } 266 267 // ciliumKubCLICommands these commands are the same as `ciliumCLICommands` but 268 // it'll run inside a container and it does not have sudo support 269 var ciliumKubCLICommands = map[string]string{ 270 "cilium endpoint list -o json": "endpoint_list.txt", 271 "cilium service list -o json": "service_list.txt", 272 "cilium config": "config.txt", 273 "cilium bpf lb list": "bpf_lb_list.txt", 274 "cilium bpf ct list global": "bpf_ct_list.txt", 275 "cilium bpf tunnel list": "bpf_tunnel_list.txt", 276 "cilium policy get": "policy_get.txt", 277 "cilium status --all-controllers": "status.txt", 278 } 279 280 // ciliumKubCLICommandsKVStore contains commands related to querying the kvstore. 281 // It is separate from ciliumKubCLICommands because it has a higher likelihood 282 // of timing out in our CI, so we want to run it separately. Otherwise, we might 283 // lose out on getting other critical debugging output when a test fails. 284 var ciliumKubCLICommandsKVStore = map[string]string{ 285 "cilium kvstore get cilium --recursive": "kvstore_get.txt", 286 } 287 288 const ( 289 ciliumEtcdOperatorSA = "cilium-etcd-operator-sa.yaml" 290 ciliumEtcdOperatorRBAC = "cilium-etcd-operator-rbac.yaml" 291 ciliumEtcdOperator = "cilium-etcd-operator.yaml" 292 ) 293 294 //GetFilePath returns the absolute path of the provided filename 295 func GetFilePath(filename string) string { 296 return fmt.Sprintf("%s/%s", BasePath, filename) 297 } 298 299 // K8s1VMName is the name of the Kubernetes master node when running K8s tests. 300 func K8s1VMName() string { 301 return fmt.Sprintf("k8s1-%s", GetCurrentK8SEnv()) 302 } 303 304 // K8s2VMName is the name of the Kubernetes worker node when running K8s tests. 305 func K8s2VMName() string { 306 return fmt.Sprintf("k8s2-%s", GetCurrentK8SEnv()) 307 }