Skip to content

Commit

Permalink
catalog onboarding (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatagarwal-ibm authored Feb 8, 2024
1 parent a9635c4 commit 7ef5358
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 49 deletions.
13 changes: 13 additions & 0 deletions .catalog-onboard-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
offerings:
- name: deploy-arch-ibm-slz-was-operator
kind: solution
catalog_id: 7df1e4ca-d54c-4fd0-82ce-3d13247308cd
offering_id: 70e68cb4-7026-4329-9faa-8a1e56444aba
variations:
- name: standard
mark_ready: false
install_type: extension
pre_validation: "tests/scripts/pre-validation-slz-roks.sh"
post_validation: "tests/scripts/post-validation-slz-roks.sh"
3 changes: 3 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
}],
["@semantic-release/exec", {
"successCmd": "echo \"SEMVER_VERSION=${nextRelease.version}\" >> $GITHUB_ENV"
}],
["@semantic-release/exec",{
"publishCmd": "./ci/trigger-catalog-onboarding-pipeline.sh --version=v${nextRelease.version}"
}]
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"ibmcloud_api_key": $VALIDATION_APIKEY,
"cluster_id": $CLUSTER_ID
"ibmcloud_api_key": $VALIDATION_APIKEY
}
19 changes: 19 additions & 0 deletions tests/other_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Tests in this file are NOT run in the PR pipeline. They are run in the continuous testing pipeline along with the ones in pr_test.go
package test

import (
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRunCompleteExample(t *testing.T) {
t.Parallel()

options := setupOptions(t, "wslo", completeExampleDir)

output, err := options.RunTestConsistency()
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
}
31 changes: 2 additions & 29 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package test

import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"os"
Expand Down Expand Up @@ -32,16 +31,6 @@ func setupOptions(t *testing.T, prefix string, exampleDir string) *testhelper.Te
return options
}

func TestRunCompleteExample(t *testing.T) {
t.Parallel()

options := setupOptions(t, "wslo", completeExampleDir)

output, err := options.RunTestConsistency()
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
}

func TestRunUpgradeExample(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -93,22 +82,6 @@ func TestRunSLZExample(t *testing.T) {
if existErr != nil {
assert.True(t, existErr == nil, "Init and Apply of temp existing resource failed")
} else {
outputClusterJson := terraform.OutputJson(t, existingTerraformOptions, "cluster_data")

var clusterID string
var clusters []struct {
ClusterID string `json:"cluster_id"`
}
// Unmarshal the JSON data into the struct
if err := json.Unmarshal([]byte(outputClusterJson), &clusters); err != nil {
fmt.Println(err)
return
}
// Loop through the clusters and find the cluster_id
for _, cluster := range clusters {
clusterID = cluster.ClusterID
}

// ------------------------------------------------------------------------------------
// Deploy WAS extension
// ------------------------------------------------------------------------------------
Expand All @@ -119,8 +92,8 @@ func TestRunSLZExample(t *testing.T) {
// Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
ImplicitRequired: false,
TerraformVars: map[string]interface{}{
"cluster_id": clusterID,
"region": region,
"cluster_id": terraform.Output(t, existingTerraformOptions, "management_cluster_id"),
"region": terraform.Output(t, existingTerraformOptions, "region"),
},
})

Expand Down
18 changes: 15 additions & 3 deletions tests/resources/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ output "prefix" {
description = "prefix"
}

output "cluster_id" {
output "region" {
value = var.region
description = "Region where SLZ ROKS Cluster is deployed."
}

output "management_cluster_id" {
value = lookup(
[for cluster in module.landing_zone.cluster_data : cluster if strcontains(cluster.resource_group_name, "management")][0], "id", ""
)
description = "management cluster ID"
}

output "workload_cluster_id" {
value = lookup(
[for cluster in module.landing_zone.cluster_data : cluster][0], "cluster_id", ""
[for cluster in module.landing_zone.cluster_data : cluster if strcontains(cluster.resource_group_name, "workload")][0], "id", ""
)
description = "cluster ID"
description = "workload cluster ID"
}
19 changes: 4 additions & 15 deletions tests/scripts/pre-validation-slz-roks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,22 @@ TF_VARS_FILE="terraform.tfvars"
# $VALIDATION_APIKEY is available in the catalog runtime
{
echo "ibmcloud_api_key=\"${VALIDATION_APIKEY}\""
echo "prefix=\"was-slz-$(openssl rand -hex 2)\""
echo "region=\"${REGION}\""
} >> ${TF_VARS_FILE}
terraform apply -input=false -auto-approve -var-file=${TF_VARS_FILE} || exit 1

prefix_var_name="prefix"
slz_prefix_var_name="landing_zone_prefix"
prefix_var_value=$(terraform output -state=terraform.tfstate -raw prefix)
rg_var_name="resource_group"
rg_var_value="${prefix_var_value}-management-rg"
region_var_name="region"
cluster_id_var_name="cluster_id"
cluster_id_value=$(terraform output -state=terraform.tfstate -raw cluster_id)
cluster_id_value=$(terraform output -state=terraform.tfstate -raw management_cluster_id)

echo "Appending '${prefix_var_name}', '${cluster_id_var_name}', '${rg_var_name}' and '${region_var_name}' input variable values to ${JSON_FILE}.."
echo "Appending '${cluster_id_var_name}' and '${region_var_name}' input variable values to ${JSON_FILE}.."

cd "${cwd}"
jq -r --arg prefix_var_name "${prefix_var_name}" \
--arg slz_prefix_var_name "${slz_prefix_var_name}" \
--arg prefix_var_value "${prefix_var_value}" \
--arg rg_var_name "${rg_var_name}" \
--arg rg_var_value "${rg_var_value}" \
--arg region_var_name "${region_var_name}" \
jq -r --arg region_var_name "${region_var_name}" \
--arg region_var_value "${REGION}" \
--arg cluster_id_var_name "${cluster_id_var_name}" \
--arg cluster_id_value "${cluster_id_value}" \
'. + {($prefix_var_name): $prefix_var_value, ($slz_prefix_var_name): $prefix_var_value, ($rg_var_name): $rg_var_value, ($region_var_name): $region_var_value}, ($cluster_id_var_name): $cluster_id_value' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1
'. + {($region_var_name): $region_var_value}, ($cluster_id_var_name): $cluster_id_value' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1

echo "Pre-validation complete successfully"
)

0 comments on commit 7ef5358

Please sign in to comment.