From fe7429d62d5a882524e5b52b5a311be5f7404d25 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 31 Jul 2024 15:58:10 +0200 Subject: [PATCH] Set the hostUrl based on provider type Signed-off-by: Carlos Eduardo Arango Gutierrez --- cmd/action/ci/ci.go | 3 +-- cmd/action/ci/entrypoint.go | 39 ++++++++++++++++++------------------- cmd/action/ci/provider.go | 3 ++- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/cmd/action/ci/ci.go b/cmd/action/ci/ci.go index a4ef0916d..929c5c5b4 100644 --- a/cmd/action/ci/ci.go +++ b/cmd/action/ci/ci.go @@ -30,8 +30,6 @@ const ( cacheFile = "/github/workspace/.cache/holodeck.yaml" kubeconfig = "/github/workspace/kubeconfig" sshKeyFile = "/github/workspace/.cache/key.pem" - // Default EC2 instance UserName for ubuntu AMI's - username = "ubuntu" ) func Run(log *logger.FunLogger) error { @@ -43,6 +41,7 @@ func Run(log *logger.FunLogger) error { } } else { if err := entrypoint(log); err != nil { + log.Error(err) if err := cleanup(log); err != nil { return err } diff --git a/cmd/action/ci/entrypoint.go b/cmd/action/ci/entrypoint.go index ada7df7fa..6e1440868 100644 --- a/cmd/action/ci/entrypoint.go +++ b/cmd/action/ci/entrypoint.go @@ -24,6 +24,7 @@ import ( "github.com/NVIDIA/holodeck/internal/logger" "github.com/NVIDIA/holodeck/pkg/jyaml" "github.com/NVIDIA/holodeck/pkg/provider/aws" + "github.com/NVIDIA/holodeck/pkg/provider/vsphere" "github.com/NVIDIA/holodeck/pkg/provisioner" "github.com/NVIDIA/holodeck/pkg/utils" ) @@ -64,30 +65,28 @@ func entrypoint(log *logger.FunLogger) error { return fmt.Errorf("failed to read cache file: %v", err) } + // Get the host url var hostUrl string - var instanceID string - var vpcID string - for _, p := range cache.Status.Properties { - switch p.Name { - case aws.PublicDnsName: - hostUrl = p.Value - case aws.InstanceID: - instanceID = p.Value - case aws.VpcID: - vpcID = p.Value - default: - continue + var username string + if cfg.Spec.Provider == v1alpha1.ProviderAWS { + username = "ubuntu" + for _, p := range cache.Status.Properties { + if p.Name == aws.PublicDnsName { + hostUrl = p.Value + break + } + } + } else if cfg.Spec.Provider == v1alpha1.ProviderVSphere { + username = "nvidia" + for _, p := range cache.Status.Properties { + if p.Name == vsphere.IpAddress { + hostUrl = p.Value + break + } } } - // Tag the instance with info the GitHub event - resources := []string{instanceID, vpcID} - tags := instanceTags() - err = provider.UpdateResourcesTags(tags, resources...) - if err != nil { - return err - } - + // Run the provisioner p, err := provisioner.New(log, sshKeyFile, username, hostUrl) if err != nil { return err diff --git a/cmd/action/ci/provider.go b/cmd/action/ci/provider.go index 2ebc81f99..03812a587 100644 --- a/cmd/action/ci/provider.go +++ b/cmd/action/ci/provider.go @@ -74,7 +74,7 @@ func newAwsProvider(log *logger.FunLogger, cfg v1alpha1.Environment) (*aws.Provi // Set auth.PrivateKey cfg.Spec.Auth.PrivateKey = sshKeyFile - cfg.Spec.Auth.Username = username + cfg.Spec.Auth.Username = "ubuntu" // Set env name setCfgName(&cfg) @@ -112,6 +112,7 @@ func newVsphereProvider(log *logger.FunLogger, cfg v1alpha1.Environment) (*vsphe // Set auth.PrivateKey cfg.Spec.Auth.PrivateKey = sshKeyFile + cfg.Spec.Auth.Username = "nvidia" // Set env name setCfgName(&cfg)