Skip to content

Commit 520bd85

Browse files
authored
Fix assorted Kubernetes issues (#511)
1 parent 0847bb8 commit 520bd85

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8
99
github.com/Azure/go-autorest/autorest/to v0.4.0
1010
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
11-
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
11+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
1212
github.com/alessio/shellescape v1.4.1 // indirect
1313
github.com/aohorodnyk/uid v1.1.0
1414
github.com/aws/aws-sdk-go v1.40.27 // indirect
@@ -22,7 +22,7 @@ require (
2222
github.com/blang/semver/v4 v4.0.0
2323
github.com/brianvoe/gofakeit/v6 v6.9.0
2424
github.com/cloudflare/gokey v0.1.0
25-
github.com/docker/go-units v0.4.0 // indirect
25+
github.com/docker/go-units v0.4.0
2626
github.com/gobwas/glob v0.2.3
2727
github.com/google/go-github/v42 v42.0.0
2828
github.com/hashicorp/hcl/v2 v2.8.0 // indirect

iterative/resource_task.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,23 @@ func resourceTaskRead(ctx context.Context, d *schema.ResourceData, m interface{}
201201
return diagnostic(diags, err, diag.Warning)
202202
}
203203

204-
keyPair, err := task.GetKeyPair(ctx)
205-
if err != nil {
206-
return diagnostic(diags, err, diag.Warning)
207-
}
208-
209-
publicKey, err := keyPair.PublicString()
210-
if err != nil {
211-
return diagnostic(diags, err, diag.Warning)
212-
}
213-
d.Set("ssh_public_key", publicKey)
204+
if keyPair, err := task.GetKeyPair(ctx); err != nil {
205+
if err != common.NotImplementedError {
206+
return diagnostic(diags, err, diag.Warning)
207+
}
208+
} else {
209+
publicKey, err := keyPair.PublicString()
210+
if err != nil {
211+
return diagnostic(diags, err, diag.Warning)
212+
}
213+
d.Set("ssh_public_key", publicKey)
214214

215-
privateKey, err := keyPair.PrivateString()
216-
if err != nil {
217-
return diagnostic(diags, err, diag.Warning)
215+
privateKey, err := keyPair.PrivateString()
216+
if err != nil {
217+
return diagnostic(diags, err, diag.Warning)
218+
}
219+
d.Set("ssh_private_key", privateKey)
218220
}
219-
d.Set("ssh_private_key", privateKey)
220221

221222
var addresses []string
222223
for _, address := range task.GetAddresses(ctx) {

task/k8s/resources/common.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"fmt"
66
"time"
77

8-
"k8s.io/apimachinery/pkg/apis/meta/v1"
8+
corev1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
"k8s.io/apimachinery/pkg/util/wait"
1011

1112
"terraform-provider-iterative/task/k8s/client"
@@ -14,13 +15,19 @@ import (
1415
// Wait for the pods matching the specified selector to pass their respective readiness probes.
1516
func WaitForPods(ctx context.Context, client *client.Client, interval time.Duration, timeout time.Duration, namespace string, selector string) (string, error) {
1617
// Retrieve all the pods matching the given selector.
17-
pods, err := client.Services.Core.Pods(namespace).
18-
List(ctx, v1.ListOptions{LabelSelector: selector})
19-
20-
if err != nil {
21-
return "", err
22-
} else if len(pods.Items) == 0 {
23-
return "", fmt.Errorf("no pods in %s matching %s", namespace, selector)
18+
var pods *corev1.PodList
19+
function := func() (done bool, err error) {
20+
pods, err = client.Services.Core.Pods(namespace).
21+
List(ctx, metav1.ListOptions{LabelSelector: selector})
22+
if err != nil {
23+
return false, err
24+
} else if len(pods.Items) > 0 {
25+
return true, nil
26+
}
27+
return false, nil
28+
}
29+
if err := wait.PollImmediate(interval, timeout, function); err != nil {
30+
return "", fmt.Errorf("no pods in %s matching %s: %w", namespace, selector, err)
2431
}
2532

2633
var podName string
@@ -29,7 +36,7 @@ func WaitForPods(ctx context.Context, client *client.Client, interval time.Durat
2936
// Define a closured function in charge of checking the state of the current pod.
3037
function := func() (bool, error) {
3138
pod, err := client.Services.Core.Pods(namespace).
32-
Get(ctx, currentPod.Name, v1.GetOptions{})
39+
Get(ctx, currentPod.Name, metav1.GetOptions{})
3340

3441
if err != nil {
3542
return false, err

task/k8s/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (t *Task) GetAddresses(ctx context.Context) []net.IP {
273273
}
274274

275275
func (t *Task) GetKeyPair(ctx context.Context) (*ssh.DeterministicSSHKeyPair, error) {
276-
return nil, common.NotFoundError
276+
return nil, common.NotImplementedError
277277
}
278278

279279
func (t *Task) GetIdentifier(ctx context.Context) common.Identifier {

0 commit comments

Comments
 (0)