Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

feat: deploy Nutanix CCM as an Addon #38

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,34 @@ func (CSI) VariableSchema() clusterv1.VariableSchema {
}

// CCM tells us to enable or disable the cloud provider interface.
type CCM struct{}
type CCM struct {
// A reference to the Secret for credential information for the target Prism Central instance
// +optional
Credentials *corev1.LocalObjectReference `json:"credentials"`
}

func (CCM) VariableSchema() clusterv1.VariableSchema {
// TODO Validate credentials is set.
// This CCM is shared across all providers.
// Some of these providers may require credentials to be set, but we don't want to require it for all providers.
// The Nutanix CCM handler will fail in at runtime if credentials are not set.
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"credentials": {
Description: "A reference to the Secret for credential information" +
"for the target Prism Central instance",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Description: "The name of the Secret",
Type: "string",
},
},
Required: []string{"name"},
},
},
},
}
}
3 changes: 2 additions & 1 deletion api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const (
CSIProviderAWSEBS = "aws-ebs"
CSIProviderNutanix = "nutanix"

CCMProviderAWS = "aws"
CCMProviderAWS = "aws"
CCMProviderNutanix = "nutanix"
)

// +kubebuilder:object:root=true
Expand Down
27 changes: 27 additions & 0 deletions api/v1alpha1/nutanix_clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
package v1alpha1

import (
"fmt"
"net/url"
"strconv"

corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -99,3 +103,26 @@ func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema
},
}
}

//nolint:gocritic // no need for named return values
func (s NutanixPrismCentralEndpointSpec) ParseURL() (string, int32, error) {
var prismCentralURL *url.URL
prismCentralURL, err := url.Parse(s.URL)
if err != nil {
return "", -1, fmt.Errorf("error parsing Prism Central URL: %w", err)
}

hostname := prismCentralURL.Hostname()

// return early with the default port if no port is specified
if prismCentralURL.Port() == "" {
return hostname, DefaultPrismCentralPort, nil
}

port, err := strconv.ParseInt(prismCentralURL.Port(), 10, 32)
if err != nil {
return "", -1, fmt.Errorf("error converting port to int: %w", err)
}

return hostname, int32(port), nil
}
7 changes: 6 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions charts/cluster-api-runtime-extensions-nutanix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ A Helm chart for cluster-api-runtime-extensions-nutanix
| deployment.replicas | int | `1` | |
| env | object | `{}` | |
| helmAddonsConfigMap | string | `"default-helm-addons-config"` | |
| hooks.ccm.nutanix.helmAddonStrategy.defaultValueTemplateConfigMap.create | bool | `true` | |
| hooks.ccm.nutanix.helmAddonStrategy.defaultValueTemplateConfigMap.name | string | `"default-nutanix-ccm-helm-values-template"` | |
| hooks.clusterAutoscaler.crsStrategy.defaultInstallationConfigMap.name | string | `"cluster-autoscaler"` | |
| hooks.clusterAutoscaler.helmAddonStrategy.defaultValueTemplateConfigMap.create | bool | `true` | |
| hooks.clusterAutoscaler.helmAddonStrategy.defaultValueTemplateConfigMap.name | string | `"default-cluster-autoscaler-helm-values-template"` | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.hooks.ccm.nutanix.helmAddonStrategy.defaultValueTemplateConfigMap.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ .Values.hooks.ccm.nutanix.helmAddonStrategy.defaultValueTemplateConfigMap.name }}'
data:
values.yaml: |-
---
prismCentralEndPoint: {{ `{{ .PrismCentralHost }}` }}
prismCentralPort: {{ `{{ .PrismCentralPort }}` }}
prismCentralInsecure: {{ `{{ .PrismCentralInsecure }}` }}
prismCentralAdditionalTrustBundle: {{ `"{{ or .PrismCentralAdditionalTrustBundle "" }}"` }}

# The Secret containing the credentials will be created by the handler.
createSecret: false
secretName: nutanix-ccm-credentials
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ data:
ChartName: node-feature-discovery
ChartVersion: 0.15.2
RepositoryURL: https://kubernetes-sigs.github.io/node-feature-discovery/charts
nutanix-ccm: |
ChartName: nutanix-cloud-provider
ChartVersion: 0.3.3
RepositoryURL: https://nutanix.github.io/helm/
nutanix-snapshot-csi: |
ChartName: nutanix-csi-snapshot
ChartVersion: v6.3.2
Expand Down
6 changes: 6 additions & 0 deletions charts/cluster-api-runtime-extensions-nutanix/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ hooks:
defaultValueTemplateConfigMap:
create: true
name: default-nutanix-csi-helm-values-template
ccm:
nutanix:
helmAddonStrategy:
defaultValueTemplateConfigMap:
create: true
name: default-nutanix-ccm-helm-values-template
nfd:
crsStrategy:
defaultInstallationConfigMap:
Expand Down
Loading
Loading