Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 8b2ac48

Browse files
committed
Replace kubectl cp with exec and re-use image name const throughout
Signed-off-by: JoshVanL <[email protected]>
1 parent 4eb7855 commit 8b2ac48

File tree

6 files changed

+45
-55
lines changed

6 files changed

+45
-55
lines changed

test/e2e/framework/framework.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/jetstack/kube-oidc-proxy/test/e2e/framework/config"
1818
"github.com/jetstack/kube-oidc-proxy/test/e2e/framework/helper"
19+
"github.com/jetstack/kube-oidc-proxy/test/kind"
1920
"github.com/jetstack/kube-oidc-proxy/test/util"
2021
)
2122

@@ -115,7 +116,7 @@ func (f *Framework) DeployProxyWith(extraVolumes []corev1.Volume, extraArgs ...s
115116
err := f.Helper().DeleteProxy(f.Namespace.Name)
116117
Expect(err).NotTo(HaveOccurred())
117118

118-
err = f.Helper().WaitForDeploymentToDelete(f.Namespace.Name, helper.ProxyName, time.Second*30)
119+
err = f.Helper().WaitForDeploymentToDelete(f.Namespace.Name, kind.ProxyImageName, time.Second*30)
119120
Expect(err).NotTo(HaveOccurred())
120121

121122
By(fmt.Sprintf("Deploying kube-oidc-proxy with extra args %s", extraArgs))

test/e2e/framework/helper/deploy.go

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ import (
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/apimachinery/pkg/util/intstr"
1717

18+
"github.com/jetstack/kube-oidc-proxy/test/kind"
1819
"github.com/jetstack/kube-oidc-proxy/test/util"
1920
)
2021

21-
const (
22-
ProxyName = "kube-oidc-proxy-e2e"
23-
IssuerName = "oidc-issuer-e2e"
24-
FakeAPIServerName = "fake-apiserver-e2e"
25-
AuditWebhookName = "audit-webhook-e2e"
26-
)
27-
2822
func (h *Helper) DeployProxy(ns *corev1.Namespace, issuerURL *url.URL, clientID string,
2923
oidcKeyBundle *util.KeyBundle, extraVolumes []corev1.Volume, extraArgs ...string) (*util.KeyBundle, *url.URL, error) {
3024
cnt := corev1.Container{
31-
Name: ProxyName,
32-
Image: ProxyName,
25+
Name: kind.ProxyImageName,
26+
Image: kind.ProxyImageName,
3327
ImagePullPolicy: corev1.PullNever,
3428
Args: append([]string{
3529
"kube-oidc-proxy",
@@ -108,7 +102,7 @@ func (h *Helper) DeployProxy(ns *corev1.Namespace, issuerURL *url.URL, clientID
108102
return nil, nil, err
109103
}
110104

111-
bundle, appURL, err := h.deployApp(ns.Name, ProxyName, corev1.ServiceTypeNodePort, cnt, volumes...)
105+
bundle, appURL, err := h.deployApp(ns.Name, kind.ProxyImageName, corev1.ServiceTypeNodePort, cnt, volumes...)
112106
if err != nil {
113107
return nil, nil, err
114108
}
@@ -118,7 +112,7 @@ func (h *Helper) DeployProxy(ns *corev1.Namespace, issuerURL *url.URL, clientID
118112

119113
crole, err := h.KubeClient.RbacV1().ClusterRoles().Create(&rbacv1.ClusterRole{
120114
ObjectMeta: metav1.ObjectMeta{
121-
GenerateName: ProxyName + "-",
115+
GenerateName: kind.ProxyImageName + "-",
122116
OwnerReferences: []metav1.OwnerReference{
123117
metav1.OwnerReference{
124118
APIVersion: "core/v1",
@@ -150,7 +144,7 @@ func (h *Helper) DeployProxy(ns *corev1.Namespace, issuerURL *url.URL, clientID
150144
_, err = h.KubeClient.RbacV1().ClusterRoleBindings().Create(
151145
&rbacv1.ClusterRoleBinding{
152146
ObjectMeta: metav1.ObjectMeta{
153-
GenerateName: ProxyName + "-",
147+
GenerateName: kind.ProxyImageName + "-",
154148
OwnerReferences: []metav1.OwnerReference{
155149
metav1.OwnerReference{
156150
APIVersion: "core/v1",
@@ -166,7 +160,7 @@ func (h *Helper) DeployProxy(ns *corev1.Namespace, issuerURL *url.URL, clientID
166160
Name: crole.Name, Kind: "ClusterRole",
167161
},
168162
Subjects: []rbacv1.Subject{
169-
{Name: ProxyName, Namespace: ns.Name, Kind: "ServiceAccount"},
163+
{Name: kind.ProxyImageName, Namespace: ns.Name, Kind: "ServiceAccount"},
170164
},
171165
})
172166
if err != nil {
@@ -178,8 +172,8 @@ func (h *Helper) DeployProxy(ns *corev1.Namespace, issuerURL *url.URL, clientID
178172

179173
func (h *Helper) DeployIssuer(ns string) (*util.KeyBundle, *url.URL, error) {
180174
cnt := corev1.Container{
181-
Name: IssuerName,
182-
Image: IssuerName,
175+
Name: kind.IssuerImageName,
176+
Image: kind.IssuerImageName,
183177
ImagePullPolicy: corev1.PullNever,
184178
Args: []string{
185179
"oidc-issuer",
@@ -202,7 +196,7 @@ func (h *Helper) DeployIssuer(ns string) (*util.KeyBundle, *url.URL, error) {
202196
},
203197
}
204198

205-
bundle, appURL, err := h.deployApp(ns, IssuerName, corev1.ServiceTypeClusterIP, cnt)
199+
bundle, appURL, err := h.deployApp(ns, kind.IssuerImageName, corev1.ServiceTypeClusterIP, cnt)
206200
if err != nil {
207201
return nil, nil, err
208202
}
@@ -212,8 +206,8 @@ func (h *Helper) DeployIssuer(ns string) (*util.KeyBundle, *url.URL, error) {
212206

213207
func (h *Helper) DeployFakeAPIServer(ns string) ([]corev1.Volume, *url.URL, error) {
214208
cnt := corev1.Container{
215-
Name: FakeAPIServerName,
216-
Image: FakeAPIServerName,
209+
Name: kind.FakeAPIServerImageName,
210+
Image: kind.FakeAPIServerImageName,
217211
ImagePullPolicy: corev1.PullNever,
218212
Args: []string{
219213
"fake-apiserver",
@@ -235,7 +229,7 @@ func (h *Helper) DeployFakeAPIServer(ns string) ([]corev1.Volume, *url.URL, erro
235229
},
236230
}
237231

238-
bundle, appURL, err := h.deployApp(ns, FakeAPIServerName, corev1.ServiceTypeClusterIP, cnt)
232+
bundle, appURL, err := h.deployApp(ns, kind.FakeAPIServerImageName, corev1.ServiceTypeClusterIP, cnt)
239233
if err != nil {
240234
return nil, nil, err
241235
}
@@ -269,8 +263,8 @@ func (h *Helper) DeployFakeAPIServer(ns string) ([]corev1.Volume, *url.URL, erro
269263

270264
func (h *Helper) DeployAuditWebhook(ns, logPath string) (corev1.Volume, *url.URL, error) {
271265
cnt := corev1.Container{
272-
Name: AuditWebhookName,
273-
Image: AuditWebhookName,
266+
Name: kind.AuditWebhookImageName,
267+
Image: kind.AuditWebhookImageName,
274268
ImagePullPolicy: corev1.PullNever,
275269
Args: []string{
276270
"audit-webhook",
@@ -293,7 +287,7 @@ func (h *Helper) DeployAuditWebhook(ns, logPath string) (corev1.Volume, *url.URL
293287
},
294288
}
295289

296-
bundle, appURL, err := h.deployApp(ns, AuditWebhookName, corev1.ServiceTypeClusterIP, cnt)
290+
bundle, appURL, err := h.deployApp(ns, kind.AuditWebhookImageName, corev1.ServiceTypeClusterIP, cnt)
297291
if err != nil {
298292
return corev1.Volume{}, nil, err
299293
}
@@ -463,13 +457,13 @@ func (h *Helper) deployApp(ns, name string, serviceType corev1.ServiceType, cont
463457
}
464458

465459
func (h *Helper) DeleteProxy(ns string) error {
466-
return h.deleteApp(ns, ProxyName, "oidc-ca")
460+
return h.deleteApp(ns, kind.ProxyImageName, "oidc-ca")
467461
}
468462
func (h *Helper) DeleteIssuer(ns string) error {
469-
return h.deleteApp(ns, IssuerName)
463+
return h.deleteApp(ns, kind.IssuerImageName)
470464
}
471465
func (h *Helper) DeleteFakeAPIServer(ns string) error {
472-
return h.deleteApp(ns, FakeAPIServerName)
466+
return h.deleteApp(ns, kind.FakeAPIServerImageName)
473467
}
474468

475469
func (h *Helper) deleteApp(ns, name string, extraSecrets ...string) error {

test/e2e/framework/helper/kubectl.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package helper
33

44
import (
5+
"io"
56
"os"
67
"os/exec"
78
"strings"
@@ -31,6 +32,10 @@ func (h *Helper) Kubectl(ns string) *Kubectl {
3132
}
3233

3334
func (k *Kubectl) Run(args ...string) error {
35+
return k.RunWithStdout(os.Stdout, args...)
36+
}
37+
38+
func (k *Kubectl) RunWithStdout(stdout io.Writer, args ...string) error {
3439
baseArgs := []string{"--kubeconfig", k.kubeconfig}
3540
if k.namespace == "" {
3641
baseArgs = append(baseArgs, "--all-namespaces")
@@ -39,7 +44,7 @@ func (k *Kubectl) Run(args ...string) error {
3944
}
4045
args = append(baseArgs, args...)
4146
cmd := exec.Command(k.kubectl, args...)
42-
cmd.Stdout = os.Stdout
47+
cmd.Stdout = stdout
4348
cmd.Stderr = os.Stderr
4449
return cmd.Run()
4550
}

test/e2e/suite/cases/audit/audit.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import (
66
"bytes"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
109
"net/http"
11-
"os"
12-
"path/filepath"
1310
"reflect"
1411
"time"
1512

@@ -160,6 +157,7 @@ func testAuditLogs(f *framework.Framework, podLabelSelector string) {
160157
}
161158

162159
By("Waiting for audit logs to be written")
160+
// 5 seconds here is longer than the proxy flush interval.
163161
time.Sleep(time.Second * 5)
164162

165163
By("Copying audit log from proxy locally")
@@ -172,23 +170,12 @@ func testAuditLogs(f *framework.Framework, podLabelSelector string) {
172170
Expect(fmt.Errorf("expected single kube-oidc-proxy pod running, got=%d", len(pods.Items))).NotTo(HaveOccurred())
173171
}
174172

175-
tmpDir, err := ioutil.TempDir(os.TempDir(), "kube-oidc-proxy-e2e")
176-
Expect(err).NotTo(HaveOccurred())
177-
178-
defer func() {
179-
err := os.RemoveAll(tmpDir)
180-
Expect(err).NotTo(HaveOccurred())
181-
}()
182-
183-
logFile := filepath.Join(tmpDir, "log.txt")
184-
185-
err = f.Helper().Kubectl(f.Namespace.Name).Run(
186-
"cp", fmt.Sprintf("%s:audit-log", pods.Items[0].Name), logFile)
187-
Expect(err).NotTo(HaveOccurred())
188-
189-
logs, err := ioutil.ReadFile(logFile)
173+
var auditLogsBuffer bytes.Buffer
174+
err = f.Helper().Kubectl(f.Namespace.Name).RunWithStdout(&auditLogsBuffer,
175+
"exec", pods.Items[0].Name, "cat", "/audit-log")
190176
Expect(err).NotTo(HaveOccurred())
191177

178+
logs := auditLogsBuffer.Bytes()
192179
scanner := bufio.NewScanner(bytes.NewReader(logs))
193180

194181
expAuditEvents := []auditv1.Event{

test/e2e/suite/cases/probe/probe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
. "github.com/onsi/gomega"
99

1010
"github.com/jetstack/kube-oidc-proxy/test/e2e/framework"
11-
"github.com/jetstack/kube-oidc-proxy/test/e2e/framework/helper"
11+
"github.com/jetstack/kube-oidc-proxy/test/kind"
1212
)
1313

1414
var _ = framework.CasesDescribe("Readiness Probe", func() {
@@ -34,7 +34,7 @@ var _ = framework.CasesDescribe("Readiness Probe", func() {
3434

3535
time.Sleep(time.Second * 10)
3636

37-
err := f.Helper().WaitForDeploymentReady(f.Namespace.Name, helper.ProxyName, time.Second*5)
37+
err := f.Helper().WaitForDeploymentReady(f.Namespace.Name, kind.ProxyImageName, time.Second*5)
3838
Expect(err).NotTo(HaveOccurred())
3939
})
4040
})

test/kind/image.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import (
1515
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
1616
)
1717

18+
const (
19+
ProxyImageName = "kube-oidc-proxy-e2e"
20+
IssuerImageName = "oidc-issuer-e2e"
21+
FakeAPIServerImageName = "fake-apiserver-e2e"
22+
AuditWebhookImageName = "audit-webhook-e2e"
23+
)
24+
1825
func (k *Kind) LoadAllImages() error {
1926
if err := k.LoadKubeOIDCProxy(); err != nil {
2027
return err
@@ -38,36 +45,32 @@ func (k *Kind) LoadAllImages() error {
3845
func (k *Kind) LoadKubeOIDCProxy() error {
3946
binPath := filepath.Join(k.rootPath, "./bin/kube-oidc-proxy-linux")
4047
mainPath := filepath.Join(k.rootPath, "./cmd/.")
41-
image := "kube-oidc-proxy-e2e"
4248

43-
return k.loadImage(binPath, mainPath, image, k.rootPath)
49+
return k.loadImage(binPath, mainPath, ProxyImageName, k.rootPath)
4450
}
4551

4652
func (k *Kind) LoadIssuer() error {
4753
binPath := filepath.Join(k.rootPath, "./test/tools/issuer/bin/oidc-issuer-linux")
4854
dockerfilePath := filepath.Join(k.rootPath, "./test/tools/issuer")
4955
mainPath := filepath.Join(dockerfilePath, "cmd")
50-
image := "oidc-issuer-e2e"
5156

52-
return k.loadImage(binPath, mainPath, image, dockerfilePath)
57+
return k.loadImage(binPath, mainPath, IssuerImageName, dockerfilePath)
5358
}
5459

5560
func (k *Kind) LoadFakeAPIServer() error {
5661
binPath := filepath.Join(k.rootPath, "./test/tools/fake-apiserver/bin/fake-apiserver-linux")
5762
dockerfilePath := filepath.Join(k.rootPath, "./test/tools/fake-apiserver")
5863
mainPath := filepath.Join(dockerfilePath, "cmd")
59-
image := "fake-apiserver-e2e"
6064

61-
return k.loadImage(binPath, mainPath, image, dockerfilePath)
65+
return k.loadImage(binPath, mainPath, FakeAPIServerImageName, dockerfilePath)
6266
}
6367

6468
func (k *Kind) LoadAuditWebhook() error {
6569
binPath := filepath.Join(k.rootPath, "./test/tools/audit-webhook/bin/audit-webhook")
6670
dockerfilePath := filepath.Join(k.rootPath, "./test/tools/audit-webhook")
6771
mainPath := filepath.Join(dockerfilePath, "cmd")
68-
image := "audit-webhook-e2e"
6972

70-
return k.loadImage(binPath, mainPath, image, dockerfilePath)
73+
return k.loadImage(binPath, mainPath, AuditWebhookImageName, dockerfilePath)
7174
}
7275

7376
func (k *Kind) loadImage(binPath, mainPath, image, dockerfilePath string) error {

0 commit comments

Comments
 (0)