Skip to content

Commit

Permalink
e2e: update context to include cluster name
Browse files Browse the repository at this point in the history
This change enables logging cluster names in the next step, improving debugging
and log readability by clearly identifying the cluster in log messages for
different operations.

- Updated Cluster struct to include Name field.
- Added `ClusterConfig` struct for cluster properties: name and kubeconfigpath.
- Added default cluster names constants
- Updated `NewContext` to ensure each cluster gets a default name if the `name`
  field is missing or empty in the config.
- Updated comment in config.yaml.sample & added name property for all clusters.
- Updated drenv/ramen.py to include cluster names along with kubeconfigpaths

  Generated drenv config:

      clusters:
        hub:
          name: hub
          kubeconfigpath: /home/pari/.config/drenv/rdr/kubeconfigs/hub
        c1:
          name: dr1
          kubeconfigpath: /home/pari/.config/drenv/rdr/kubeconfigs/dr1
        c2:
          name: dr2
          kubeconfigpath: /home/pari/.config/drenv/rdr/kubeconfigs/dr2

Signed-off-by: Parikshith <[email protected]>
  • Loading branch information
parikshithb authored and nirs committed Feb 27, 2025
1 parent 19dd1b0 commit 65236e1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
11 changes: 7 additions & 4 deletions e2e/config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ pvcspecs:
accessmodes: ReadWriteMany

# Sample cluster configurations:
# Uncomment and edit the following lines to provide the kubeconfig paths
# for your test clusters.
# Uncomment and edit the following lines to set cluster names
# and their kubeconfig paths for the managed and hub clusters.
# Clusters:
# c1:
# kubeconfigpath: /path/to/kubeconfig/c1
# name: dr1
# kubeconfigpath: /path/to/kubeconfig/dr1
# c2:
# kubeconfigpath: /path/to/kubeconfig/c2
# name: dr2
# kubeconfigpath: /path/to/kubeconfig/dr2
# hub:
# name: hub
# kubeconfigpath: /path/to/kubeconfig/hub
10 changes: 6 additions & 4 deletions e2e/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ type PVCSpec struct {
AccessModes string
UnsupportedDeployers []string
}
type ClusterConfig struct {
Name string
KubeconfigPath string
}
type TestConfig struct {
// User configurable values.
ChannelNamespace string
GitURL string
Clusters map[string]struct {
KubeconfigPath string
}
PVCSpecs []PVCSpec
Clusters map[string]ClusterConfig
PVCSpecs []PVCSpec

// Generated values
channelName string
Expand Down
25 changes: 25 additions & 0 deletions e2e/util/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
var ConfigFile string

type Cluster struct {
Name string
Client ctrlClient.Client
}

Expand All @@ -39,6 +40,12 @@ type Context struct {

var Ctx *Context

const (
defaultHubClusterName = "hub"
defaultC1ClusterName = "c1"
defaultC2ClusterName = "c2"
)

func addToScheme(scheme *runtime.Scheme) error {
if err := ocmv1b1.AddToScheme(scheme); err != nil {
return err
Expand Down Expand Up @@ -102,16 +109,34 @@ func NewContext(log *zap.SugaredLogger, configFile string) (*Context, error) {
panic(err)
}

ctx.Hub.Name = config.Clusters["hub"].Name
if ctx.Hub.Name == "" {
ctx.Hub.Name = defaultHubClusterName
log.Infof("Cluster \"hub\" name not set, using default name %q", defaultHubClusterName)
}

ctx.Hub.Client, err = setupClient(config.Clusters["hub"].KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to create clients for hub cluster: %w", err)
}

ctx.C1.Name = config.Clusters["c1"].Name
if ctx.C1.Name == "" {
ctx.C1.Name = defaultC1ClusterName
log.Infof("Cluster \"c1\" name not set, using default name %q", defaultC1ClusterName)
}

ctx.C1.Client, err = setupClient(config.Clusters["c1"].KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to create clients for c1 cluster: %w", err)
}

ctx.C2.Name = config.Clusters["c2"].Name
if ctx.C2.Name == "" {
ctx.C2.Name = defaultC2ClusterName
log.Infof("Cluster \"c2\" name not set, using default name %q", defaultC2ClusterName)
}

ctx.C2.Client, err = setupClient(config.Clusters["c2"].KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to create clients for c2 cluster: %w", err)
Expand Down
5 changes: 4 additions & 1 deletion test/drenv/ramen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def dump_e2e_config(env):
with open(path, "w") as f:
f.write(data)

e2e_config["Clusters"][e2e_name] = {"kubeconfigpath": path}
e2e_config["Clusters"][e2e_name] = {
"name": cluster_name,
"kubeconfigpath": path,
}

path = os.path.join(base, "config.yaml")
with open(path, "w") as f:
Expand Down

0 comments on commit 65236e1

Please sign in to comment.