Skip to content

Commit

Permalink
feat: Support all Palette TF provider configuration options (#29)
Browse files Browse the repository at this point in the history
* feat: support configuring retries, trace

Signed-off-by: Tyler Gillson <[email protected]>

* test: QOL improvements

Signed-off-by: Tyler Gillson <[email protected]>

---------

Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson authored Aug 22, 2024
1 parent a7a5c4d commit 89eab94
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
18 changes: 10 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
"args": [
"--debug",
"--terraform-version=1.3.3",
"--terraform-provider-version=0.19.2",
"--terraform-provider-version=0.21.0",
"--terraform-provider-source=spectrocloud/spectrocloud"
],
"env": {
"KUBECONFIG": "/Users/tylergillson/Downloads/oam-dev.kubeconfig",
// "TF_REATTACH_PROVIDERS": "{\"registry.terraform.io/spectrocloud/spectrocloud\":{\"Protocol\":\"grpc\",\"ProtocolVersion\":5,\"Pid\":100,\"Test\":true,\"Addr\":{\"Network\":\"unix\",\"String\":\"/var/folders/w1/sm7f2fb959j2xkxln196ksj40000gn/T/plugin2559404211\"}}}",
"UPBOUND_CONTEXT": "local"
"KUBECONFIG": "",
"UPBOUND_CONTEXT": "local",
"TF_PID": "",
"TF_ADDR": "",
},
// "showLog": true,
// "trace": "verbose",
Expand All @@ -31,11 +32,12 @@
"mode": "auto",
"program": "${workspaceFolder}/tests/integration/suite_test.go",
"env": {
"KUBECONFIG": "",
"KUBEBUILDER_ASSETS": "/Users/tylergillson/spectrocloud/repos/oss/spectrocloud/provider-palette/.cache/tools/darwin_arm64/k8s/1.30.0-darwin-arm64",
"KUBECONFIG": "/Users/tylergillson/Downloads/vdev.kubeconfig",
"KUBEBUILDER_ASSETS": "/Users/tylergillson/spectrocloud/repos/oss/spectrocloud/provider-palette/.cache/tools/darwin_arm64/k8s/1.29.3-darwin-arm64",
"TERRAFORM_VERSION": "1.3.3",
"TERRAFORM_PROVIDER_VERSION": "0.19.2",
// "TF_REATTACH_PROVIDERS": "{\"registry.terraform.io/spectrocloud/spectrocloud\":{\"Protocol\":\"grpc\",\"ProtocolVersion\":5,\"Pid\":5045,\"Test\":true,\"Addr\":{\"Network\":\"unix\",\"String\":\"/var/folders/w1/sm7f2fb959j2xkxln196ksj40000gn/T/plugin2100568909\"}}}",
"TERRAFORM_PROVIDER_VERSION": "0.21.0",
"TF_PID": "87062",
"TF_ADDR": "/var/folders/w1/sm7f2fb959j2xkxln196ksj40000gn/T/plugin616341282"
},
},
]
Expand Down
13 changes: 8 additions & 5 deletions internal/clients/palette.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ const (
const (
keyAPIEndpoint = "host"
keyAPIKey = "api_key"
keyProjectName = "project_name"
keyInsecure = "ignore_insecure_tls_error"
keyProjectName = "project_name"
keyRetries = "retry_attempts"
keyTrace = "trace"

// Palette credentials environment variable names

Expand Down Expand Up @@ -74,14 +76,15 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr
}

// set provider configuration

ps.Configuration = map[string]interface{}{
keyAPIEndpoint: paletteCreds[keyAPIEndpoint],
keyProjectName: paletteCreds[keyProjectName],
keyAPIKey: paletteCreds[keyAPIKey],
keyProjectName: paletteCreds[keyProjectName],
}
if v, ok := paletteCreds[keyInsecure]; ok {
ps.Configuration[keyInsecure] = v
for _, k := range []string{keyInsecure, keyRetries, keyTrace} {
if v, ok := paletteCreds[k]; ok {
ps.Configuration[k] = v
}
}

// set environment variables for sensitive provider configuration
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/cloudaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ var _ = Describe("Cloud Account Tests", Ordered, func() {
},
},
}

err := kclient.Create(tc, awsCloudAccount)
if err != nil {
_ = kclient.Delete(tc, awsCloudAccount)
}
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() bool {
Expand Down
48 changes: 39 additions & 9 deletions tests/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
kerrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
Expand All @@ -41,6 +43,28 @@ var (
ts *httptest.Server
)

func init() {
// Configure TF_REATTACH_PROVIDERS
addr := os.Getenv("TF_ADDR")
pid := os.Getenv("TF_PID")
if addr == "" || pid == "" {
return
}
reattachProvider := fmt.Sprintf(`{
"registry.terraform.io/spectrocloud/spectrocloud": {
"Protocol": "grpc",
"ProtocolVersion": 5,
"Pid": %s,
"Test": true,
"Addr": {
"Network": "unix",
"String": "%s"
}
}
}`, pid, addr)
os.Setenv("TF_REATTACH_PROVIDERS", reattachProvider)
}

func TestFunctionality(t *testing.T) {
RegisterFailHandler(Fail)

Expand Down Expand Up @@ -138,8 +162,9 @@ func initResources() {
Name: "crossplane-system",
},
}
err := kclient.Create(tc, ns)
Expect(err).ShouldNot(HaveOccurred())
if err := kclient.Create(tc, ns); err != nil && !kerrs.IsAlreadyExists(err) {
Fail(fmt.Sprintf("failed to create namespace: %v", err))
}

s := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -151,15 +176,19 @@ func initResources() {
"api_key": "dummy",
"project_name": "Default",
"host": "%s",
"ignore_insecure_tls_error": "true"
"ignore_insecure_tls_error": "true",
"retry_attempts": "1",
"trace": "true"
}`,
// Configure provider-palette to use the mock Palette server
ts.Listener.Addr().String(),
ts.Listener.Addr().String(), // hook provider-palette's TF host into the Palette mock server
),
},
}
err = kclient.Create(tc, s)
Expect(err).ShouldNot(HaveOccurred())
if err := kclient.Get(tc, types.NamespacedName{Name: s.Name, Namespace: s.Namespace}, &corev1.Secret{}); err == nil {
Expect(kclient.Delete(tc, s)).Should(Succeed())
time.Sleep(interval)
}
Expect(kclient.Create(tc, s)).Should(Succeed())

pc := &v1beta1.ProviderConfig{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -181,6 +210,7 @@ func initResources() {
},
},
}
err = kclient.Create(tc, pc)
Expect(err).ShouldNot(HaveOccurred())
if err := kclient.Create(tc, pc); err != nil && !kerrs.IsAlreadyExists(err) {
Fail(fmt.Sprintf("failed to create ProviderConfig: %v", err))
}
}

0 comments on commit 89eab94

Please sign in to comment.