Skip to content

Commit

Permalink
Add initial support for deploying onto Nutanix. Add Nutanix deprovisi…
Browse files Browse the repository at this point in the history
…oning support.
  • Loading branch information
eliorerz committed Feb 20, 2025
1 parent 9dfda92 commit c092981
Show file tree
Hide file tree
Showing 33 changed files with 1,196 additions and 10 deletions.
14 changes: 14 additions & 0 deletions apis/hive/v1/clusterdeprovision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
import (
"github.com/openshift/hive/apis/hive/v1/aws"
"github.com/openshift/hive/apis/hive/v1/azure"
"github.com/openshift/hive/apis/hive/v1/nutanix"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -54,6 +55,8 @@ type ClusterDeprovisionPlatform struct {
Ovirt *OvirtClusterDeprovision `json:"ovirt,omitempty"`
// IBMCloud contains IBM Cloud specific deprovision settings
IBMCloud *IBMClusterDeprovision `json:"ibmcloud,omitempty"`
// Nutanix contains Nutanix-specific deprovision settings
Nutanix *NutanixClusterDeprovision `json:"nutanix,omitempty"`
}

// AWSClusterDeprovision contains AWS-specific configuration for a ClusterDeprovision
Expand Down Expand Up @@ -154,6 +157,17 @@ type IBMClusterDeprovision struct {
BaseDomain string `json:"baseDomain"`
}

// NutanixClusterDeprovision contains Nutanix-specific configuration for a ClusterDeprovision
type NutanixClusterDeprovision struct {
// PrismCentral is the endpoint (address and port) to connect to the Prism Central.
// This serves as the default Prism-Central.
PrismCentral nutanix.PrismEndpoint `json:"prismCentral"`

// CredentialsSecretRef refers to a secret that contains the Nutanix account access
// credentials.
CredentialsSecretRef corev1.LocalObjectReference `json:"credentialsSecretRef"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
18 changes: 18 additions & 0 deletions apis/hive/v1/nutanix/platform.go
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"`
}
18 changes: 18 additions & 0 deletions apis/hive/v1/nutanix/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions apis/hive/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions config/crds/hive.openshift.io_clusterdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,45 @@ spec:
nutanix:
description: Nutanix is the configuration used when installing
on Nutanix Prism Central.
properties:
credentialsSecretRef:
description: |-
CredentialsSecretRef refers to a secret that contains the Nutanix account access
credentials.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
prismCentral:
description: |-
PrismCentral is the endpoint (address and port) to connect to the Prism Central.
This serves as the default Prism-Central.
properties:
address:
description: address is the endpoint address (DNS name
or IP address) of the Nutanix Prism Central or Element
(cluster)
type: string
port:
description: port is the port number to access the Nutanix
Prism Central or Element (cluster)
format: int32
type: integer
required:
- address
- port
type: object
required:
- credentialsSecretRef
- prismCentral
type: object
openstack:
description: OpenStack is the configuration used when installing
Expand Down
42 changes: 42 additions & 0 deletions config/crds/hive.openshift.io_clusterdeprovisions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,48 @@ spec:
- credentialsSecretRef
- region
type: object
nutanix:
description: Nutanix contains Nutanix-specific deprovision settings
properties:
credentialsSecretRef:
description: |-
CredentialsSecretRef refers to a secret that contains the Nutanix account access
credentials.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
prismCentral:
description: |-
PrismCentral is the endpoint (address and port) to connect to the Prism Central.
This serves as the default Prism-Central.
properties:
address:
description: address is the endpoint address (DNS name
or IP address) of the Nutanix Prism Central or Element
(cluster)
type: string
port:
description: port is the port number to access the Nutanix
Prism Central or Element (cluster)
format: int32
type: integer
required:
- address
- port
type: object
required:
- credentialsSecretRef
- prismCentral
type: object
openstack:
description: OpenStack contains OpenStack-specific deprovision
settings
Expand Down
39 changes: 39 additions & 0 deletions config/crds/hive.openshift.io_clusterpools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,45 @@ spec:
nutanix:
description: Nutanix is the configuration used when installing
on Nutanix Prism Central.
properties:
credentialsSecretRef:
description: |-
CredentialsSecretRef refers to a secret that contains the Nutanix account access
credentials.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
prismCentral:
description: |-
PrismCentral is the endpoint (address and port) to connect to the Prism Central.
This serves as the default Prism-Central.
properties:
address:
description: address is the endpoint address (DNS name
or IP address) of the Nutanix Prism Central or Element
(cluster)
type: string
port:
description: port is the port number to access the Nutanix
Prism Central or Element (cluster)
format: int32
type: integer
required:
- address
- port
type: object
required:
- credentialsSecretRef
- prismCentral
type: object
openstack:
description: OpenStack is the configuration used when installing
Expand Down
1 change: 1 addition & 0 deletions contrib/pkg/deprovision/deprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewDeprovisionCommand() *cobra.Command {
cmd.AddCommand(NewDeprovisionOpenStackCommand())
cmd.AddCommand(NewDeprovisionvSphereCommand())
cmd.AddCommand(NewDeprovisionOvirtCommand())
cmd.AddCommand(NewDeprovisionNutanixCommand())
return cmd
}

Expand Down
120 changes: 120 additions & 0 deletions contrib/pkg/deprovision/nutanix.go
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
}
Loading

0 comments on commit c092981

Please sign in to comment.