istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/cluster/fake.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 cluster 16 17 import ( 18 "k8s.io/apimachinery/pkg/version" 19 20 "istio.io/istio/pkg/kube" 21 ) 22 23 var _ Cluster = FakeCluster{} 24 25 func init() { 26 RegisterFactory(Fake, newFakeCluster) 27 } 28 29 func NewFake(name, major, minor string) Cluster { 30 c, _ := newFakeCluster( 31 Config{ 32 Meta: map[string]any{ 33 "majorVersion": major, 34 "minorVersion": minor, 35 }, 36 }, 37 Topology{ 38 ClusterKind: Fake, 39 ClusterName: name, 40 AllClusters: map[string]Cluster{}, 41 }, 42 ) 43 c.(*FakeCluster).Topology.AllClusters[c.Name()] = c 44 return c 45 } 46 47 func newFakeCluster(cfg Config, topology Topology) (Cluster, error) { 48 return &FakeCluster{ 49 CLIClient: kube.NewFakeClient(), 50 Topology: topology, 51 Version: &version.Info{ 52 Major: cfg.Meta.String("majorVesion"), 53 Minor: cfg.Meta.String("minorVersion"), 54 }, 55 }, nil 56 } 57 58 // FakeCluster used for testing. 59 type FakeCluster struct { 60 kube.CLIClient 61 Version *version.Info 62 Topology 63 } 64 65 func (f FakeCluster) GetKubernetesVersion() (*version.Info, error) { 66 return f.Version, nil 67 }