Skip to content

Commit

Permalink
Update client for secrets client
Browse files Browse the repository at this point in the history
Signed-off-by: Charly Molter <charly.molter@konghq.com>
  • Loading branch information
lahabana committed Sep 14, 2021
1 parent 26a8837 commit 40b6ea6
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 211 deletions.
9 changes: 5 additions & 4 deletions app/kuma-cp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -46,7 +47,7 @@ func newRunCmd() *cobra.Command {
}

type runCmdOpts struct {
SetupSignalHandler func() (stopCh <-chan struct{})
SetupSignalHandler func() context.Context
}

func newRunCmdWithOpts(opts runCmdOpts) *cobra.Command {
Expand All @@ -64,8 +65,8 @@ func newRunCmdWithOpts(opts runCmdOpts) *cobra.Command {
runLog.Error(err, "could not load the configuration")
return err
}
closeCh := opts.SetupSignalHandler()
rt, err := bootstrap.Bootstrap(cfg, closeCh)
ctx := opts.SetupSignalHandler()
rt, err := bootstrap.Bootstrap(ctx, cfg)
if err != nil {
runLog.Error(err, "unable to set up Control Plane runtime")
return err
Expand Down Expand Up @@ -184,7 +185,7 @@ func newRunCmdWithOpts(opts runCmdOpts) *cobra.Command {
}

runLog.Info("starting Control Plane", "version", kuma_version.Build.Version)
if err := rt.Start(closeCh); err != nil {
if err := rt.Start(ctx.Done()); err != nil {
runLog.Error(err, "problem running Control Plane")
return err
}
Expand Down
10 changes: 5 additions & 5 deletions app/kuma-cp/cmd/run_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -32,14 +33,12 @@ func (f ConfigFactoryFunc) GenerateConfig() string {

func RunSmokeTest(factory ConfigFactory, workdir string) {
Describe("run", func() {
var stopCh chan struct{}
var errCh chan error
var configFile *os.File

var diagnosticsPort int

JustBeforeEach(func() {
stopCh = make(chan struct{})
errCh = make(chan error)

freePort, _, err := addr.Suggest()
Expand Down Expand Up @@ -67,9 +66,10 @@ func RunSmokeTest(factory ConfigFactory, workdir string) {
config := fmt.Sprintf(factory.GenerateConfig(), diagnosticsPort)
_, err := configFile.WriteString(config)
Expect(err).ToNot(HaveOccurred())
ctx, cancel := context.WithCancel(context.Background())
cmd := newRunCmdWithOpts(runCmdOpts{
SetupSignalHandler: func() <-chan struct{} {
return stopCh
SetupSignalHandler: func() context.Context {
return ctx
},
})
cmd.SetArgs([]string{"--config-file=" + configFile.Name()})
Expand Down Expand Up @@ -105,7 +105,7 @@ func RunSmokeTest(factory ConfigFactory, workdir string) {

// when
By("signaling Control Plane to stop")
close(stopCh)
cancel()

// then
err = <-errCh
Expand Down
4 changes: 2 additions & 2 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ func writeFile(filename string, data []byte, perm os.FileMode) error {

func setupQuitChannel() chan struct{} {
quit := make(chan struct{})
quitOnSignal := core.SetupSignalHandler()
appCtx := core.SetupSignalHandler()
go func() {
<-quitOnSignal
<-appCtx.Done()
runLog.Info("Kuma DP caught an exit signal")
if quit != nil {
close(quit)
Expand Down
22 changes: 9 additions & 13 deletions app/kuma-dp/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"context"
"fmt"
"io"
"io/ioutil"
Expand All @@ -25,26 +26,21 @@ import (
)

var _ = Describe("run", func() {

var backupSetupSignalHandler func() <-chan struct{}
var backupSetupSignalHandler func() context.Context
var ctx context.Context
var cancel func()

BeforeEach(func() {
backupSetupSignalHandler = core.SetupSignalHandler
ctx, cancel = context.WithCancel(context.Background())
core.SetupSignalHandler = func() context.Context {
return ctx
}
})
AfterEach(func() {
core.SetupSignalHandler = backupSetupSignalHandler
})

var stopCh chan struct{}

BeforeEach(func() {
stopCh = make(chan struct{})

core.SetupSignalHandler = func() <-chan struct{} {
return stopCh
}
})

var tmpDir string

BeforeEach(func() {
Expand Down Expand Up @@ -156,7 +152,7 @@ var _ = Describe("run", func() {

// when
By("signaling the dataplane manager to stop")
close(stopCh)
cancel()

// then
err = <-errCh
Expand Down
2 changes: 1 addition & 1 deletion app/kuma-prometheus-sd/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func newRunCmd() *cobra.Command {
discovery := adapter.NewAdapter(ctx, cfg.Prometheus.OutputFile, "xds_sd", discoverer, util_log.NewLogger(runLog.WithName("xds_sd"), "adapter"))
discovery.Run()

<-setupSignalHandler()
<-setupSignalHandler().Done()
return nil
},
}
Expand Down
28 changes: 12 additions & 16 deletions app/kuma-prometheus-sd/cmd/run_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
package cmd

import (
"context"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/kumahq/kuma/pkg/core"
"github.com/kumahq/kuma/pkg/test"
)

var _ = Describe("run", func() {

var backupSetupSignalHandler func() <-chan struct{}
var backupSetupSignalHandler func() context.Context
var ctx context.Context
var cancel func()

BeforeEach(func() {
backupSetupSignalHandler = setupSignalHandler
backupSetupSignalHandler = core.SetupSignalHandler
ctx, cancel = context.WithCancel(context.Background())
core.SetupSignalHandler = func() context.Context {
return ctx
}
})

AfterEach(func() {
setupSignalHandler = backupSetupSignalHandler
})

var stopCh chan struct{}

BeforeEach(func() {
stopCh = make(chan struct{})

setupSignalHandler = func() <-chan struct{} {
return stopCh
}
core.SetupSignalHandler = backupSetupSignalHandler
})

XIt("should be possible to run `kuma-prometheus-sd run`", test.Within(15*time.Second, func() {
Expand All @@ -49,7 +45,7 @@ var _ = Describe("run", func() {

// when
By("signaling Kuma Prometheus SD to stop")
close(stopCh)
cancel()

// then
err := <-errCh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ spec:
metadata:
annotations:
checksum/config: 6df33ec160599ac1a5e9fda109e2ba0d02c865f926ac14ecf92895e96b70a228
checksum/tls-secrets: 8d96524f2edd766fb63fe05db26d83be9f7d7a5823e0878040d4a6ab95446e78
checksum/tls-secrets: fbd975366a9b6c3adc0c329ec90b8632d96f24bd6b98ce8e77f4911ef89c8f84
labels:
app.kubernetes.io/name: kuma
app.kubernetes.io/instance: kuma
Expand Down Expand Up @@ -1095,7 +1095,7 @@ metadata:
app.kubernetes.io/instance: kuma
webhooks:
- name: mesh.defaulter.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand All @@ -1115,7 +1115,7 @@ webhooks:
- meshes
sideEffects: None
- name: owner-reference.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1147,7 +1147,7 @@ webhooks:

sideEffects: None
- name: kuma-injector.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Ignore
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1177,7 +1177,7 @@ metadata:
app.kubernetes.io/instance: kuma
webhooks:
- name: validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1214,7 +1214,7 @@ webhooks:

sideEffects: None
- name: service.validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Ignore
clientConfig:
caBundle: XYZ
Expand All @@ -1234,7 +1234,7 @@ webhooks:
- services
sideEffects: None
- name: secret.validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
namespaceSelector:
matchLabels:
kuma.io/system-namespace: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ spec:
metadata:
annotations:
checksum/config: 6df33ec160599ac1a5e9fda109e2ba0d02c865f926ac14ecf92895e96b70a228
checksum/tls-secrets: 8d96524f2edd766fb63fe05db26d83be9f7d7a5823e0878040d4a6ab95446e78
checksum/tls-secrets: fbd975366a9b6c3adc0c329ec90b8632d96f24bd6b98ce8e77f4911ef89c8f84
labels:
app.kubernetes.io/name: kuma
app.kubernetes.io/instance: kuma
Expand Down Expand Up @@ -920,7 +920,7 @@ metadata:
app.kubernetes.io/instance: kuma
webhooks:
- name: mesh.defaulter.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand All @@ -940,7 +940,7 @@ webhooks:
- meshes
sideEffects: None
- name: owner-reference.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -972,7 +972,7 @@ webhooks:

sideEffects: None
- name: kuma-injector.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Ignore
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1002,7 +1002,7 @@ metadata:
app.kubernetes.io/instance: kuma
webhooks:
- name: validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1039,7 +1039,7 @@ webhooks:

sideEffects: None
- name: service.validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Ignore
clientConfig:
caBundle: XYZ
Expand All @@ -1059,7 +1059,7 @@ webhooks:
- services
sideEffects: None
- name: secret.validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
namespaceSelector:
matchLabels:
kuma.io/system-namespace: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ spec:
metadata:
annotations:
checksum/config: 6df33ec160599ac1a5e9fda109e2ba0d02c865f926ac14ecf92895e96b70a228
checksum/tls-secrets: 8d96524f2edd766fb63fe05db26d83be9f7d7a5823e0878040d4a6ab95446e78
checksum/tls-secrets: fbd975366a9b6c3adc0c329ec90b8632d96f24bd6b98ce8e77f4911ef89c8f84
labels:
app.kubernetes.io/name: kuma
app.kubernetes.io/instance: kuma
Expand Down Expand Up @@ -926,7 +926,7 @@ metadata:
app.kubernetes.io/instance: kuma
webhooks:
- name: mesh.defaulter.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand All @@ -946,7 +946,7 @@ webhooks:
- meshes
sideEffects: None
- name: owner-reference.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -978,7 +978,7 @@ webhooks:

sideEffects: None
- name: kuma-injector.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Ignore
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1008,7 +1008,7 @@ metadata:
app.kubernetes.io/instance: kuma
webhooks:
- name: validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Fail
clientConfig:
caBundle: XYZ
Expand Down Expand Up @@ -1045,7 +1045,7 @@ webhooks:

sideEffects: None
- name: service.validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
failurePolicy: Ignore
clientConfig:
caBundle: XYZ
Expand All @@ -1065,7 +1065,7 @@ webhooks:
- services
sideEffects: None
- name: secret.validator.kuma-admission.kuma.io
admissionReviewVersions: ["v1"]
admissionReviewVersions: ["v1beta1", "v1"]
namespaceSelector:
matchLabels:
kuma.io/system-namespace: "true"
Expand Down
Loading

0 comments on commit 40b6ea6

Please sign in to comment.