istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/gcemetadata/gcemetadata.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 gcemetadata provides basic utilities around configuring the fake 16 // GCE Metadata Server component for integration testing. 17 package gcemetadata 18 19 import ( 20 "istio.io/istio/pkg/test" 21 "istio.io/istio/pkg/test/framework/components/cluster" 22 "istio.io/istio/pkg/test/framework/resource" 23 ) 24 25 // Instance represents a deployed GCE Metadata Server app instance. 26 type Instance interface { 27 // Address is the IP Address of the service provided by the fake GCE 28 // Metadata Server. 29 Address() string 30 // Address is the IP Address of the service provided by the fake GCE 31 // Metadata Server to be used for "VM" instances 32 AddressVM() string 33 } 34 35 // Config defines the options for creating an fake GCE Metadata Server component. 36 type Config struct { 37 // Cluster to be used in a multicluster environment 38 Cluster cluster.Cluster 39 } 40 41 // New returns a new instance of stackdriver. 42 func New(ctx resource.Context, c Config) (i Instance, err error) { 43 return newKube(ctx, c) 44 } 45 46 // NewOrFail returns a new GCE Metadata Server instance or fails test. 47 func NewOrFail(t test.Failer, ctx resource.Context, c Config) Instance { 48 t.Helper() 49 i, err := New(ctx, c) 50 if err != nil { 51 t.Fatalf("gcemetadata.NewOrFail: %v", err) 52 } 53 54 return i 55 }