Skip to content

Commit

Permalink
replace openstack user credentials with application credentials in cl…
Browse files Browse the repository at this point in the history
…uster and machinedeployment tests
  • Loading branch information
nrobert13 committed Jul 4, 2024
1 parent bed2ab8 commit 9f21856
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 97 deletions.
6 changes: 2 additions & 4 deletions metakube/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const (
testEnvOpenstackNodeDC = "METAKUBE_OPENSTACK_NODE_DC"
testEnvOpenstackApplicationCredentialsID = "METAKUBE_OPENSTACK_APPLICATION_CREDENTIALS_ID"
testEnvOpenstackApplicationCredentialsSecret = "METAKUBE_OPENSTACK_APPLICATION_CREDENTIALS_SECRET"
testEnvOpenstackUsername = "METAKUBE_OPENSTACK_USERNAME"
testEnvOpenstackAuthURL = "METAKUBE_OPENSTACK_AUTH_URL"
testEnvOpenstackPassword = "METAKUBE_OPENSTACK_PASSWORD"
testEnvOpenstackProjectID = "METAKUBE_OPENSTACK_PROJECT_ID"
testEnvOpenstackProjectName = "METAKUBE_OPENSTACK_PROJECT_NAME"
testEnvOpenstackRegion = "METAKUBE_OPENSTACK_REGION"
Expand Down Expand Up @@ -81,8 +79,8 @@ func testAccPreCheckForOpenstack(t *testing.T) {
t.Helper()
testAccPreCheck(t)
checkEnv(t, testEnvK8sVersionOpenstack)
checkEnv(t, testEnvOpenstackUsername)
checkEnv(t, testEnvOpenstackPassword)
checkEnv(t, testEnvOpenstackApplicationCredentialsID)
checkEnv(t, testEnvOpenstackApplicationCredentialsSecret)
checkEnv(t, testEnvOpenstackProjectID)
checkEnv(t, testEnvOpenstackProjectName)
checkEnv(t, testEnvOpenstackRegion)
Expand Down
136 changes: 67 additions & 69 deletions metakube/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func TestAccMetakubeCluster_Openstack_Basic(t *testing.T) {

resourceName := "metakube_cluster.acctest_cluster"
data := &clusterOpenstackBasicData{
Name: makeRandomName() + "-basic",
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackUser: os.Getenv(testEnvOpenstackUsername),
OpenstackPassword: os.Getenv(testEnvOpenstackPassword),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
Version: os.Getenv(testEnvK8sVersionOpenstack),
Name: makeRandomName() + "-basic",
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackApplicationCredentialsID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialsSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
Version: os.Getenv(testEnvK8sVersionOpenstack),
}
var config strings.Builder
if err := clusterOpenstackBasicTemplate.Execute(&config, data); err != nil {
Expand Down Expand Up @@ -222,18 +222,18 @@ func TestAccMetakubeCluster_Openstack_ApplicationCredentials_Dynammic(t *testing
var cluster models.Cluster
resourceName := "metakube_cluster.acctest_cluster"
data := &clusterOpenstackApplicationCredentailsData{
Name: makeRandomName() + "-appcred-dynamic",
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackUser: os.Getenv(testEnvOpenstackUsername),
OpenstackPassword: os.Getenv(testEnvOpenstackPassword),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
Version: os.Getenv(testEnvK8sVersionOpenstack),
OpenstackApplicationCredentialID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
Dynamic: true,
Name: makeRandomName() + "-appcred-dynamic",
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackApplicationCredentialsID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialsSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
Version: os.Getenv(testEnvK8sVersionOpenstack),
OpenstackApplicationCredentialID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
Dynamic: true,
}
var config strings.Builder
if err := clusterOpenstackApplicationCredentialsBasicTemplate.Execute(&config, data); err != nil {
Expand Down Expand Up @@ -267,15 +267,15 @@ func TestAccMetakubeCluster_Openstack_UpgradeVersion(t *testing.T) {
resourceName := "metakube_cluster.acctest_cluster"
versionedConfig := func(version string) string {
data := &clusterOpenstackBasicData{
Name: makeRandomName() + "-upgrade",
Version: version,
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackUser: os.Getenv(testEnvOpenstackUsername),
OpenstackPassword: os.Getenv(testEnvOpenstackPassword),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
Name: makeRandomName() + "-upgrade",
Version: version,
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackApplicationCredentialsID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialsSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
}
var result strings.Builder
if err := clusterOpenstackBasicTemplate.Execute(&result, data); err != nil {
Expand Down Expand Up @@ -315,11 +315,11 @@ func TestAccMetakubeCluster_Openstack_UpgradeVersion(t *testing.T) {
}

type clusterOpenstackBasicData struct {
OpenstackAuthURL string
OpenstackUser string
OpenstackPassword string
OpenstackProjectID string
OpenstackRegion string
OpenstackAuthURL string
OpenstackApplicationCredentialsID string
OpenstackApplicationCredentialsSecret string
OpenstackProjectID string
OpenstackRegion string

Name string
DatacenterName string
Expand All @@ -342,9 +342,8 @@ terraform {
provider "openstack" {
auth_url = "{{ .OpenstackAuthURL }}"
user_name = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
tenant_id = "{{ .OpenstackProjectID }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
region = "{{ .OpenstackRegion }}"
}
Expand Down Expand Up @@ -372,10 +371,10 @@ resource "metakube_cluster" "acctest_cluster" {
}
cloud {
openstack {
user_credentials {
application_credentials {
project_id = "{{ .OpenstackProjectID }}"
username = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
}
floating_ip_pool = "ext-net"
security_group = openstack_networking_secgroup_v2.cluster-net.name
Expand Down Expand Up @@ -426,11 +425,11 @@ resource "openstack_networking_subnet_v2" "subnet_tf_test" {
}`)

type clusterOpenstackApplicationCredentailsData struct {
OpenstackAuthURL string
OpenstackUser string
OpenstackPassword string
OpenstackProjectID string
OpenstackRegion string
OpenstackAuthURL string
OpenstackApplicationCredentialsID string
OpenstackApplicationCredentialsSecret string
OpenstackProjectID string
OpenstackRegion string

Name string
DatacenterName string
Expand All @@ -453,9 +452,8 @@ terraform {
{{ if .Dynamic }}
provider "openstack" {
auth_url = "{{ .OpenstackAuthURL }}"
user_name = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
tenant_id = "{{ .OpenstackProjectID }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
region = "{{ .OpenstackRegion }}"
}
Expand Down Expand Up @@ -544,13 +542,13 @@ func TestAccMetakubeCluster_SSHKeys(t *testing.T) {
resourceName := "metakube_cluster.acctest_cluster"

data := &clusterOpenstackWithSSHKeyData{
Name: makeRandomName() + "-sshkeys",
OpenstackUser: os.Getenv(testEnvOpenstackUsername),
OpenstackPassword: os.Getenv(testEnvOpenstackPassword),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
Version: os.Getenv(testEnvK8sVersionOpenstack),
Name: makeRandomName() + "-sshkeys",
OpenstackApplicationCredentialsID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialsSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
Version: os.Getenv(testEnvK8sVersionOpenstack),
}

var config1 strings.Builder
Expand Down Expand Up @@ -591,13 +589,13 @@ func TestAccMetakubeCluster_SSHKeys(t *testing.T) {
}

type clusterOpenstackWithSSHKeyData struct {
Name string
DatacenterName string
ProjectID string
Version string
OpenstackProjectID string
OpenstackUser string
OpenstackPassword string
Name string
DatacenterName string
ProjectID string
Version string
OpenstackProjectID string
OpenstackApplicationCredentialsID string
OpenstackApplicationCredentialsSecret string
}

var clusterOpenstackTemplateWithSSHKey1 = mustParseTemplate("clusterOpenstackWithSSHKey1", `
Expand All @@ -615,10 +613,10 @@ resource "metakube_cluster" "acctest_cluster" {
enable_ssh_agent = true
cloud {
openstack {
user_credentials {
application_credentials {
project_id = "{{ .OpenstackProjectID }}"
username = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
}
floating_ip_pool = "ext-net"
}
Expand Down Expand Up @@ -647,10 +645,10 @@ resource "metakube_cluster" "acctest_cluster" {
enable_ssh_agent = true
cloud {
openstack {
user_credentials {
application_credentials {
project_id = "{{ .OpenstackProjectID }}"
username = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
}
floating_ip_pool = "ext-net"
}
Expand Down
47 changes: 23 additions & 24 deletions metakube/resource_node_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ func TestAccMetakubeNodeDeployment_Openstack_Basic(t *testing.T) {
serverGroupResourceName := "openstack_compute_servergroup_v2.acctest_sg"

data := &nodeDeploymentBasicData{
Name: makeRandomName() + "-os-nodedepl",
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackUser: os.Getenv(testEnvOpenstackUsername),
OpenstackPassword: os.Getenv(testEnvOpenstackPassword),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
ClusterVersion: os.Getenv(testEnvK8sVersionOpenstack),
KubeletVersion: os.Getenv(testEnvK8sOlderVersion),
NodeFlavor: os.Getenv(testEnvOpenstackFlavor),
OSVersion: os.Getenv(testEnvOpenstackImage),
UseFloatingIP: "false",
Name: makeRandomName() + "-os-nodedepl",
OpenstackAuthURL: os.Getenv(testEnvOpenstackAuthURL),
OpenstackApplicationCredentialsID: os.Getenv(testEnvOpenstackApplicationCredentialsID),
OpenstackApplicationCredentialsSecret: os.Getenv(testEnvOpenstackApplicationCredentialsSecret),
OpenstackProjectID: os.Getenv(testEnvOpenstackProjectID),
OpenstackRegion: os.Getenv(testEnvOpenstackRegion),
DatacenterName: os.Getenv(testEnvOpenstackNodeDC),
ProjectID: os.Getenv(testEnvProjectID),
ClusterVersion: os.Getenv(testEnvK8sVersionOpenstack),
KubeletVersion: os.Getenv(testEnvK8sOlderVersion),
NodeFlavor: os.Getenv(testEnvOpenstackFlavor),
OSVersion: os.Getenv(testEnvOpenstackImage),
UseFloatingIP: "false",
}

var config strings.Builder
Expand Down Expand Up @@ -137,11 +137,11 @@ func TestAccMetakubeNodeDeployment_Openstack_Basic(t *testing.T) {
}

type nodeDeploymentBasicData struct {
OpenstackAuthURL string
OpenstackUser string
OpenstackPassword string
OpenstackProjectID string
OpenstackRegion string
OpenstackAuthURL string
OpenstackApplicationCredentialsID string
OpenstackApplicationCredentialsSecret string
OpenstackProjectID string
OpenstackRegion string

Name string
DatacenterName string
Expand All @@ -165,9 +165,8 @@ var nodeDeploymentBasicTemplate = mustParseTemplate("nodeDeploymentBasic", `
}
provider "openstack" {
auth_url = "{{ .OpenstackAuthURL }}"
user_name = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
tenant_id = "{{ .OpenstackProjectID }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
region = "{{ .OpenstackRegion }}"
}
Expand All @@ -189,10 +188,10 @@ var nodeDeploymentBasicTemplate = mustParseTemplate("nodeDeploymentBasic", `
version = "{{ .ClusterVersion }}"
cloud {
openstack {
user_credentials {
application_credentials {
project_id = "{{ .OpenstackProjectID }}"
username = "{{ .OpenstackUser }}"
password = "{{ .OpenstackPassword }}"
application_credential_id = "{{ .OpenstackApplicationCredentialsID }}"
application_credential_secret = "{{ .OpenstackApplicationCredentialsSecret }}"
}
floating_ip_pool = "ext-net"
}
Expand Down

0 comments on commit 9f21856

Please sign in to comment.