...

Source file src/edge-infra.dev/test/framework/k8s/config.go

Documentation: edge-infra.dev/test/framework/k8s

     1  package k8s
     2  
     3  import (
     4  	"time"
     5  
     6  	"edge-infra.dev/test/framework"
     7  	"edge-infra.dev/test/framework/config"
     8  	"edge-infra.dev/test/framework/gcp"
     9  )
    10  
    11  // Timeouts has configuration values for K8s specific timeouts
    12  var Timeouts struct {
    13  	DefaultTimeout time.Duration `default:"30s" description:"default timeout for k8s operations"`
    14  	Tick           time.Duration `default:"1s" description:"default tick interval for k8s operations to be retried"`
    15  	InstallTimeout time.Duration `default:"60s" description:"default timeout for installing components"`
    16  	// Add additional specialized timeouts here based on objects worked with,
    17  	// e.g., PVC binding, etc. Default should cover most basic K8s interactions
    18  }
    19  
    20  // Runtime has configuration values related to the cluster runtime
    21  var Runtime struct {
    22  	GKE bool `default:"false" description:"whether or not the test is being ran against a GKE cluster"`
    23  }
    24  
    25  // KonfigKonnector has configuration values needed for installing & configuring
    26  // K8s config connector
    27  var KonfigKonnector struct {
    28  	APIKey         string `description:"path to key.json for service account that will be used with k8s cfg connector, required for non-GKE test runs"`
    29  	ServiceAccount string `description:"service account name to use when configurng k8s cfg connector on GKE via workload identity"`
    30  }
    31  
    32  func init() {
    33  	_ = config.AddOptions(&Timeouts, "k8s")
    34  	_ = config.AddOptions(&Runtime, "k8s")
    35  	_ = config.AddOptions(&KonfigKonnector, "k8s-cfg-conn")
    36  }
    37  
    38  // NeedsKonfigKonnector is a function that can be hooked in as a framework.Step
    39  // so that test suites which require K8s cfg connector for integration tests are
    40  // automatically skipped if the pre-reqs aren't provided.
    41  // Only skips if the test is an integration test.
    42  func NeedsKonfigKonnector(f *framework.Framework) {
    43  	// tests relying on KCC to create resources will need a valid GCP project ID
    44  	// to schedule resources against
    45  	gcp.NeedsProjectID(f)
    46  
    47  	if Runtime.GKE && KonfigKonnector.ServiceAccount == "" {
    48  		f.Skip("KonfigKonnector", "missing service account for GKE runtime")
    49  	}
    50  
    51  	if !Runtime.GKE && KonfigKonnector.APIKey == "" {
    52  		f.Skip("KonfigKonnector", "missing key.json for non-GKE runtime")
    53  	}
    54  }
    55  

View as plain text