istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/cluster/kube/cluster.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 kube 16 17 import ( 18 "bytes" 19 "fmt" 20 21 "istio.io/istio/pkg/kube" 22 "istio.io/istio/pkg/test/framework/components/cluster" 23 "istio.io/istio/pkg/test/framework/components/echo" 24 ) 25 26 var _ echo.Cluster = &Cluster{} 27 28 // Cluster for a Kubernetes cluster. Provides access via a kube.Client. 29 type Cluster struct { 30 // filename is the path to the kubeconfig file for this cluster. 31 filename string 32 33 // vmSupport indicates the cluster is being used for fake VMs 34 vmSupport bool 35 36 // CLIClient is embedded to interact with the kube cluster. 37 kube.CLIClient 38 39 // Topology is embedded to include common functionality. 40 cluster.Topology 41 } 42 43 // CanDeploy for a kube cluster returns true if the config is a non-vm, or if the cluster supports 44 // fake pod-based VMs. 45 func (c *Cluster) CanDeploy(config echo.Config) (echo.Config, bool) { 46 if config.DeployAsVM && !c.isVMSupported() { 47 return echo.Config{}, false 48 } 49 return config, true 50 } 51 52 func (c *Cluster) isVMSupported() bool { 53 // VMs can only be deployed on config clusters, since they assume the cluster ID of the control plane. 54 return c.IsConfig() && c.vmSupport 55 } 56 57 // OverrideTopology allows customizing the relationship between this and other clusters 58 // for a single suite. This practice is discouraged, and separate test jobs should be created 59 // on a per-topology bassis. 60 // TODO remove this when centralistiod test is isolated as it's own job 61 func (c *Cluster) OverrideTopology(fn func(cluster.Topology) cluster.Topology) { 62 c.Topology = fn(c.Topology) 63 } 64 65 func (c *Cluster) String() string { 66 buf := &bytes.Buffer{} 67 68 _, _ = fmt.Fprint(buf, c.Topology.String()) 69 _, _ = fmt.Fprintf(buf, "Filename: %s\n", c.filename) 70 71 return buf.String() 72 } 73 74 // Filename of the kubeconfig file for this cluster. 75 // TODO(nmittler): Remove the need for this by changing operator to use provided kube clients directly. 76 func (c Cluster) Filename() string { 77 return c.filename 78 }