Skip to content

Commit c67e5b2

Browse files
authored
Kubernetes support (#56)
* Add experimental support for Kubernetes * Add documentation for Kubernetes * Add golden tests for iterative/resource_runner.go * Vendor dependencies to follow the project approach * Fix provisioner code newlines to avoid tripping restyled * Bump release Go version to 0.16 Failing to do so would produce build errors when dealing with M1 processors and sibling darwin_arm64 architectures. failed to build for darwin_arm64: # terraform-provider-iterative /opt/hostedtoolcache/go/1.14.15/x64/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /tmp/go-link-210080194/go.o: file not recognized: File format not recognized collect2: error: ld returned 1 exit status * Standardize Kubernetes resource identifiers * Retrieve the namespace from the kubeconfig context Previously, the namespace was hardcoded to the value "iterative"; now it uses the namespace specified on the provided Kubernetes configuration or the "default" namespace otherwise. * Adapt the identifier generator for Kubernetes compatibility Identifiers were being generated through the time-based github.com/teris-io/shortid module, which uses a fixed 64-character alphabet that includes uppercase letters and underscores. Unfortunately, that alphabet is rejected by Kubernetes because of these "disallowed" characters: kubernetes/kubernetes#71140 Now identifiers are valid 64-bit base 36 [0-9a-z] strings generated with the system CSPRNG. Given that the previous 64^9 identifier finite field is 1024 times smaller than the new 2^64 one, this change should not pose any greater collision risk. * Fix documentation blunder * Remove vendor directory * Restyle with gofmt * Unstage outdated modifications Revert stale clone-amis.go Update README.md Update README.md Update README.md Update README.md Update README.md Apply suggestions from code review Apply suggestions from code review * Merge changes from upstream README.md * Skip deletion of nonexistent Kubernetes machines * Replace the runner script interpreter process with exec In order to transfer the graceful shutdown SIGTERM signal to our NodeJS cml-runner script, we need to run the startup_script with bash as the container entry point and replace the bash interpreter with the node interpreter through an exec call so the later can handle the container signals properly. * Remove Kubernetes support from the documentation * Fix formatting issues
1 parent c09d620 commit c67e5b2

14 files changed

+1032
-30
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Set up Go
2929
uses: actions/setup-go@v2
3030
with:
31-
go-version: 1.14
31+
go-version: 1.16
3232

3333
- name: Import GPG key
3434
id: import_gpg
@@ -44,4 +44,4 @@ jobs:
4444
args: release --rm-dist
4545
env:
4646
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
47-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

go.mod

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,37 @@ require (
88
github.com/Azure/go-autorest/autorest v0.11.13 // indirect
99
github.com/Azure/go-autorest/autorest/azure/auth v0.5.3
1010
github.com/Azure/go-autorest/autorest/to v0.4.0
11+
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
12+
github.com/ChrisTrenkamp/goxpath v0.0.0-20190607011252-c5096ec8773d // indirect
13+
github.com/aohorodnyk/uid v1.1.0
14+
github.com/apparentlymart/go-cidr v1.1.0 // indirect
15+
github.com/apparentlymart/go-userdirs v0.0.0-20200915174352-b0c018a67c13 // indirect
16+
github.com/apparentlymart/go-versions v1.0.1 // indirect
1117
github.com/aws/aws-sdk-go v1.34.13
12-
github.com/hashicorp/terraform v0.14.2 // indirect
18+
github.com/gofrs/uuid v3.3.0+incompatible // indirect
19+
github.com/hashicorp/aws-sdk-go-base v0.6.0 // indirect
20+
github.com/hashicorp/go-getter v1.5.1 // indirect
21+
github.com/hashicorp/hcl/v2 v2.8.0 // indirect
22+
github.com/hashicorp/terraform v0.13.0-beta1 // indirect
1323
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0
24+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
25+
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
26+
github.com/masterzen/winrm v0.0.0-20200615185753-c42b5136ff88 // indirect
27+
github.com/mitchellh/gox v1.0.1 // indirect
28+
github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db // indirect
29+
github.com/sebdah/goldie/v2 v2.5.3 // indirect
1430
github.com/stretchr/testify v1.6.1
1531
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
32+
github.com/tombuildsstuff/giovanni v0.12.0 // indirect
1633
github.com/zclconf/go-cty v1.7.0 // indirect
34+
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
1735
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
36+
golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb // indirect
37+
google.golang.org/api v0.34.0 // indirect
38+
gopkg.in/alessio/shellescape.v1 v1.0.0-20170105083845-52074bc9df61 // indirect
39+
k8s.io/api v0.20.5
40+
k8s.io/apimachinery v0.20.5
41+
k8s.io/client-go v0.20.5
42+
k8s.io/klog v0.4.0 // indirect
43+
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e // indirect
1844
)

go.sum

Lines changed: 142 additions & 0 deletions
Large diffs are not rendered by default.

iterative/aws/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net"
78
"regexp"
89
"sort"
910
"strconv"
@@ -15,6 +16,8 @@ import (
1516
"github.com/aws/aws-sdk-go/service/ec2"
1617
"github.com/aws/aws-sdk-go/service/sts"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
20+
"terraform-provider-iterative/iterative/utils"
1821
)
1922

2023
//ResourceMachineCreate creates AWS instance
@@ -414,3 +417,7 @@ func decodeAWSError(region string, err error) error {
414417

415418
return fmt.Errorf("Not able to decode: %s", err.Error())
416419
}
420+
421+
func ResourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
422+
return utils.RunCommand("journalctl --no-pager", 10*time.Second, net.JoinHostPort(d.Get("instance_ip").(string), "22"), "ubuntu", d.Get("ssh_private").(string))
423+
}

iterative/azure/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net"
78
"os"
89
"strings"
910
"time"
@@ -16,6 +17,8 @@ import (
1617
"github.com/Azure/go-autorest/autorest/to"
1718

1819
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20+
21+
"terraform-provider-iterative/iterative/utils"
1922
)
2023

2124
//ResourceMachineCreate creates AWS instance
@@ -392,3 +395,7 @@ func subscriptionID() (string, error) {
392395

393396
return "", errors.New("AZURE_SUBSCRIPTION_ID is not present")
394397
}
398+
399+
func ResourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
400+
return utils.RunCommand("journalctl --no-pager", 10*time.Second, net.JoinHostPort(d.Get("instance_ip").(string), "22"), "ubuntu", d.Get("ssh_private").(string))
401+
}

0 commit comments

Comments
 (0)