Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default credential names if credential names are not set #5324

Merged
merged 1 commit into from
Mar 22, 2023
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
5 changes: 4 additions & 1 deletion pkg/providers/nutanix/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ func (ntb *TemplateBuilder) GenerateEKSASpecSecret(clusterSpec *cluster.Spec, bu
// EKSASecretName returns the name of the secret containing the credentials for the nutanix prism central and is used by the
// EKS-Anywhere controller.
func EKSASecretName(spec *cluster.Spec) string {
return spec.NutanixDatacenter.Spec.CredentialRef.Name
if spec.NutanixDatacenter.Spec.CredentialRef != nil {
thunderboltsid marked this conversation as resolved.
Show resolved Hide resolved
return spec.NutanixDatacenter.Spec.CredentialRef.Name
}
return constants.NutanixCredentialsName
}

func (ntb *TemplateBuilder) generateSpecSecret(secretName string, creds credentials.BasicAuthCredential, buildOptions ...providers.BuildMapOption) ([]byte, error) {
Expand Down
19 changes: 19 additions & 0 deletions pkg/providers/nutanix/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ func TestNewNutanixTemplateBuilderGenerateSpecSecretFailure(t *testing.T) {
assert.Error(t, err)
}

func TestNewNutanixTemplateBuilderGenerateSpecSecretDefaultCreds(t *testing.T) {
dcConf, machineConf, workerConfs := minimalNutanixConfigSpec(t)
t.Setenv(constants.NutanixUsernameKey, "admin")
t.Setenv(constants.NutanixPasswordKey, "password")
creds := GetCredsFromEnv()
builder := NewNutanixTemplateBuilder(&dcConf.Spec, &machineConf.Spec, &machineConf.Spec, workerConfs, creds, time.Now)
assert.NotNil(t, builder)

buildSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster-no-credentialref.yaml")

secretSpec, err := builder.GenerateCAPISpecSecret(buildSpec)
assert.NoError(t, err)
assert.NotNil(t, secretSpec)

secretSpec, err = builder.GenerateEKSASpecSecret(buildSpec)
assert.NoError(t, err)
assert.NotNil(t, secretSpec)
}

func TestNutanixTemplateBuilderGenerateCAPISpecForCreateWithAutoscalingConfiguration(t *testing.T) {
dcConf, machineConf, workerConfs := minimalNutanixConfigSpec(t)

Expand Down
72 changes: 72 additions & 0 deletions pkg/providers/nutanix/testdata/eksa-cluster-no-credentialref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: Cluster
metadata:
name: eksa-unit-test
namespace: default
spec:
kubernetesVersion: "1.19"
controlPlaneConfiguration:
name: eksa-unit-test
count: 3
endpoint:
host: test-ip
machineGroupRef:
name: eksa-unit-test
kind: NutanixMachineConfig
workerNodeGroupConfigurations:
- count: 4
name: eksa-unit-test
machineGroupRef:
name: eksa-unit-test
kind: NutanixMachineConfig
externalEtcdConfiguration:
name: eksa-unit-test
count: 3
machineGroupRef:
name: eksa-unit-test
kind: NutanixMachineConfig
datacenterRef:
kind: NutanixDatacenterConfig
name: eksa-unit-test
clusterNetwork:
cni: "cilium"
pods:
cidrBlocks:
- 192.168.0.0/16
services:
cidrBlocks:
- 10.96.0.0/12
---
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: NutanixDatacenterConfig
metadata:
name: eksa-unit-test
namespace: default
spec:
endpoint: "prism.nutanix.com"
port: 9440
---
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: NutanixMachineConfig
metadata:
name: eksa-unit-test
namespace: default
spec:
vcpusPerSocket: 1
vcpuSockets: 4
memorySize: 8Gi
image:
type: "name"
name: "prism-image"
cluster:
type: "name"
name: "prism-cluster"
subnet:
type: "name"
name: "prism-subnet"
systemDiskSize: 40Gi
osFamily: "ubuntu"
users:
- name: "mySshUsername"
sshAuthorizedKeys:
- "mySshAuthorizedKey"