-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for deploying onto Nutanix. Add Nutanix deprovisi…
…oning support.
- Loading branch information
Showing
33 changed files
with
1,196 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
package nutanix | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
// Platform stores any global configuration used for Nutanix platform | ||
type Platform struct { | ||
// PrismCentral is the endpoint (address and port) to connect to the Prism Central. | ||
// This serves as the default Prism-Central. | ||
PrismCentral PrismEndpoint `json:"prismCentral"` | ||
|
||
// CredentialsSecretRef refers to a secret that contains the Nutanix account access | ||
// credentials. | ||
CredentialsSecretRef corev1.LocalObjectReference `json:"credentialsSecretRef"` | ||
} | ||
|
||
// PrismEndpoint holds the endpoint address and port to access the Nutanix Prism Central or Element (cluster) | ||
type PrismEndpoint struct { | ||
// address is the endpoint address (DNS name or IP address) of the Nutanix Prism Central or Element (cluster) | ||
Address string `json:"address"` | ||
|
||
// port is the port number to access the Nutanix Prism Central or Element (cluster) | ||
Port int32 `json:"port"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package deprovision | ||
|
||
import ( | ||
"fmt" | ||
"github.com/openshift/hive/contrib/pkg/utils" | ||
nutanixutils "github.com/openshift/hive/contrib/pkg/utils/nutanix" | ||
"github.com/openshift/hive/pkg/constants" | ||
"github.com/openshift/installer/pkg/destroy/nutanix" | ||
"github.com/openshift/installer/pkg/types" | ||
typesnutanix "github.com/openshift/installer/pkg/types/nutanix" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
// nutanixOptions | ||
type nutanixOptions struct { | ||
logLevel string | ||
infraID string | ||
endpoint string | ||
port string | ||
username string | ||
password string | ||
} | ||
|
||
func NewDeprovisionNutanixCommand() *cobra.Command { | ||
opt := &nutanixOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "nutanix INFRAID", | ||
Short: "Deprovision Nutanix assets (as created by openshift-installer)", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := opt.Complete(cmd, args); err != nil { | ||
log.WithError(err).Fatal("failed to complete options") | ||
} | ||
if err := opt.Validate(cmd); err != nil { | ||
log.WithError(err).Fatal("validation failed") | ||
} | ||
if err := opt.Run(); err != nil { | ||
log.WithError(err).Fatal("Runtime error") | ||
} | ||
}, | ||
} | ||
flags := cmd.Flags() | ||
flags.StringVar(&opt.logLevel, "loglevel", "info", "log level, one of: debug, info, warn, error, fatal, panic") | ||
flags.StringVar(&opt.endpoint, "nutanix-pc-address", "", "Domain name or IP address of the Nutanix Prism Central endpoint") | ||
flags.StringVar(&opt.port, "nutanix-pc-port", "", "Port of the Nutanix Prism Central endpoint") | ||
return cmd | ||
} | ||
|
||
// Complete finishes parsing arguments for the command | ||
func (o *nutanixOptions) Complete(cmd *cobra.Command, args []string) error { | ||
o.infraID = args[0] | ||
|
||
client, err := utils.GetClient("hiveutil-deprovision-nutanix") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get client") | ||
} | ||
nutanixutils.ConfigureCreds(client) | ||
|
||
return nil | ||
} | ||
|
||
// Validate ensures that option values make sense | ||
func (o *nutanixOptions) Validate(cmd *cobra.Command) error { | ||
if o.endpoint == "" { | ||
o.endpoint = os.Getenv(constants.NutanixPrismCentralEndpointEnvVar) | ||
if o.endpoint == "" { | ||
return fmt.Errorf("must provide --nutanix-pc-address or set %s env var", constants.NutanixPrismCentralEndpointEnvVar) | ||
} | ||
} | ||
|
||
if o.port == "" { | ||
o.port = os.Getenv(constants.NutanixPrismCentralPortEnvVar) | ||
if o.port == "" { | ||
return fmt.Errorf("must provide --nutanix-pc-port or set %s env var", constants.NutanixPrismCentralPortEnvVar) | ||
} | ||
} | ||
|
||
o.username = os.Getenv(constants.NutanixUsernameEnvVar) | ||
if o.username == "" { | ||
return fmt.Errorf("no %s env var set, cannot proceed", constants.NutanixUsernameEnvVar) | ||
} | ||
o.password = os.Getenv(constants.NutanixPasswordEnvVar) | ||
if o.password == "" { | ||
return fmt.Errorf("no %s env var set, cannot proceed", constants.NutanixPasswordEnvVar) | ||
} | ||
return nil | ||
} | ||
|
||
// Run executes the command | ||
func (o *nutanixOptions) Run() error { | ||
logger, err := utils.NewLogger(o.logLevel) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
metadata := &types.ClusterMetadata{ | ||
InfraID: o.infraID, | ||
ClusterPlatformMetadata: types.ClusterPlatformMetadata{ | ||
Nutanix: &typesnutanix.Metadata{ | ||
PrismCentral: o.endpoint, | ||
Username: o.username, | ||
Password: o.password, | ||
Port: o.port, | ||
}, | ||
}, | ||
} | ||
|
||
destroyer, err := nutanix.New(logger, metadata) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// ClusterQuota stomped in return | ||
_, err = destroyer.Run() | ||
return err | ||
} |
Oops, something went wrong.