...

Source file src/github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/config/config.go

Documentation: github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/config

     1  // Copyright 2021 Chaos Mesh 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  
    16  package config
    17  
    18  import (
    19  	"flag"
    20  
    21  	"k8s.io/client-go/tools/clientcmd"
    22  	clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
    23  	"k8s.io/kubernetes/test/e2e/framework"
    24  
    25  	test "github.com/chaos-mesh/chaos-mesh/e2e-test"
    26  )
    27  
    28  // TestConfig for the test config
    29  var TestConfig = test.NewDefaultConfig()
    30  
    31  // RegisterOperatorFlags registers flags for chaos-mesh.
    32  func RegisterOperatorFlags(flags *flag.FlagSet) {
    33  	flags.StringVar(&TestConfig.ManagerImage, "manager-image-registry", "ghcr.io", "chaos-mesh image registry")
    34  	flags.StringVar(&TestConfig.ManagerImage, "manager-image", "chaos-mesh/chaos-mesh", "chaos-mesh image")
    35  	flags.StringVar(&TestConfig.ManagerTag, "manager-image-tag", "latest", "chaos-mesh image tag")
    36  	flags.StringVar(&TestConfig.DaemonImage, "daemon-image-registry", "ghcr.io", "chaos-daemon image registry")
    37  	flags.StringVar(&TestConfig.DaemonImage, "daemon-image", "chaos-mesh/chaos-daemon", "chaos-daemon image")
    38  	flags.StringVar(&TestConfig.DaemonTag, "daemon-image-tag", "latest", "chaos-daemon image tag")
    39  	flags.StringVar(&TestConfig.E2EImage, "e2e-image", "chaos-mesh/e2e-helper:latest", "e2e-helper image")
    40  	flags.StringVar(&TestConfig.ChaosCoreDNSImage, "chaos-coredns-image", "chaos-mesh/chaos-coredns:v0.2.6", "chaos-coredns image")
    41  	flags.StringVar(&TestConfig.PauseImage, "pause-image", "gcr.io/google-containers/pause:latest", "custom pause container image for pod failure chaos")
    42  	flags.BoolVar(&TestConfig.InstallChaosMesh, "install-chaos-mesh", false, "automatically install chaos-mesh")
    43  	flags.BoolVar(&TestConfig.EnableDashboard, "enable-dashboard", false, "enable Chaos Dashboard")
    44  }
    45  
    46  // LoadClientRawConfig would provide client raw config
    47  func LoadClientRawConfig() (clientcmdapi.Config, error) {
    48  	loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
    49  	loadingRules.ExplicitPath = framework.TestContext.KubeConfig
    50  	overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults}
    51  	if framework.TestContext.KubeContext != "" {
    52  		overrides.CurrentContext = framework.TestContext.KubeContext
    53  	}
    54  	return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides).RawConfig()
    55  }
    56