Skip to content

Commit

Permalink
Fix kubernetes v1.20+ selfLink generation & upgrade k3s to v1.20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinbunney committed Feb 8, 2021
1 parent 28792b6 commit ff37406
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 64 deletions.
55 changes: 0 additions & 55 deletions _examples/crds/basic_crd.tf

This file was deleted.

5 changes: 2 additions & 3 deletions kubernetes/data_source_kubectl_filename_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func TestAccKubectlDataSourceFilenameList_basic(t *testing.T) {
{
Config: testAccKubernetesDataSourceFilenameListConfig_basic(path + "/*"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.kubectl_filename_list.test", "matches.#", "2"),
resource.TestCheckResourceAttr("data.kubectl_filename_list.test", "matches.0", path+"/basic_crd.tf"),
resource.TestCheckResourceAttr("data.kubectl_filename_list.test", "matches.1", path+"/couchbase.tf"),
resource.TestCheckResourceAttr("data.kubectl_filename_list.test", "matches.#", "1"),
resource.TestCheckResourceAttr("data.kubectl_filename_list.test", "matches.0", path+"/couchbase.tf"),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions kubernetes/resource_kubectl_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func visit(files *[]string) filepath.WalkFunc {
}

func TestAcckubectlYaml(t *testing.T) {
_ = os.Setenv("KUBECTL_PROVIDER_APPLY_RETRY_COUNT", "5")
var files []string
root := "../_examples"
err := filepath.Walk(root, visit(&files))
Expand Down
10 changes: 9 additions & 1 deletion kubernetes/resource_kubectl_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,15 @@ var kubernetesControlFields = map[string]bool{
// to generate a consistent, unique ID for our Terraform resources.
func generateSelfLink(apiVersion, namespace, kind, name string) string {
var b strings.Builder
b.WriteString("/apis")

// for any v1 api served objects, they used to be served from /api
// all others are served from /apis
if apiVersion == "v1" {
b.WriteString("/api")
} else {
b.WriteString("/apis")
}

if len(apiVersion) != 0 {
fmt.Fprintf(&b, "/%s", apiVersion)
}
Expand Down
8 changes: 5 additions & 3 deletions kubernetes/resource_kubectl_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,13 @@ func TestGetLiveManifestFilteredForUserProvidedOnly(t *testing.T) {
func TestGenerateSelfLink(t *testing.T) {
// general case
link := generateSelfLink("v1", "ns", "kind", "name")
assert.Equal(t, link, "/apis/v1/namespaces/ns/kinds/name")
assert.Equal(t, link, "/api/v1/namespaces/ns/kinds/name")
// no-namespace case
link = generateSelfLink("v1", "", "kind", "name")
assert.Equal(t, link, "/apis/v1/kinds/name")
assert.Equal(t, link, "/api/v1/kinds/name")
// plural kind adds 'es'
link = generateSelfLink("v1", "ns", "kinds", "name")
assert.Equal(t, link, "/apis/v1/namespaces/ns/kindses/name")
assert.Equal(t, link, "/api/v1/namespaces/ns/kindses/name")
link = generateSelfLink("apps/v1", "ns", "Deployment", "name")
assert.Equal(t, link, "/apis/apps/v1/namespaces/ns/deployments/name")
}
4 changes: 2 additions & 2 deletions scripts/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
server:
image: rancher/k3s:v1.0.1
image: rancher/k3s:v1.20.2-k3s1
command: server --disable-agent --tls-san 172.17.0.1
environment:
- K3S_CLUSTER_SECRET=somethingtotallyrandom
Expand All @@ -13,7 +13,7 @@ services:
- 6443:6443

node:
image: rancher/k3s:v1.0.1
image: rancher/k3s:v1.20.2-k3s1
tmpfs:
- /run
- /var/run
Expand Down

0 comments on commit ff37406

Please sign in to comment.