istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/istioctl/istioctl.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 istioctl
    16  
    17  import (
    18  	"fmt"
    19  
    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 "istioctl"
    26  type Instance interface {
    27  	// WaitForConfig will wait until all passed in config has been distributed
    28  	WaitForConfig(defaultNamespace string, configs string) error
    29  
    30  	// Invoke invokes an istioctl command and returns the output and exception.
    31  	// stdout and stderr will be returned as different strings
    32  	Invoke(args []string) (string, string, error)
    33  
    34  	// InvokeOrFail calls Invoke and fails tests if it returns en err
    35  	InvokeOrFail(t test.Failer, args []string) (string, string)
    36  }
    37  
    38  // Config is structured config for the istioctl component
    39  type Config struct {
    40  	// Cluster to be used in a multicluster environment
    41  	Cluster cluster.Cluster
    42  }
    43  
    44  // New returns a new instance of "istioctl".
    45  func New(ctx resource.Context, cfg Config) (i Instance, err error) {
    46  	return newKube(ctx, cfg)
    47  }
    48  
    49  // NewOrFail returns a new instance of "istioctl".
    50  func NewOrFail(t test.Failer, c resource.Context, config Config) Instance {
    51  	i, err := New(c, config)
    52  	if err != nil {
    53  		t.Fatalf("istioctl.NewOrFail:: %v", err)
    54  	}
    55  
    56  	return i
    57  }
    58  
    59  func (c *Config) String() string {
    60  	result := ""
    61  	result += fmt.Sprintf("Cluster:                      %s\n", c.Cluster)
    62  	return result
    63  }