Skip to content

Commit a0cf870

Browse files
committed
Flags for apiserver
1 parent 36e10f9 commit a0cf870

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

pkg/cache/cache_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232
)
3333

34+
const testNamespaceOne = "test-namespace-1"
35+
const testNamespaceTwo = "test-namespace-2"
36+
3437
var informerCache cache.Cache
3538
var stop chan struct{}
3639
var knownPod1 runtime.Object
@@ -74,9 +77,9 @@ var _ = Describe("Informer Cache", func() {
7477
Expect(cfg).NotTo(BeNil())
7578

7679
By("creating three pods")
77-
knownPod1 = createPod("test-pod-1", "test-namespace-1", kcorev1.RestartPolicyNever)
78-
knownPod2 = createPod("test-pod-2", "test-namespace-2", kcorev1.RestartPolicyAlways)
79-
knownPod3 = createPod("test-pod-3", "test-namespace-2", kcorev1.RestartPolicyOnFailure)
80+
knownPod1 = createPod("test-pod-1", testNamespaceOne, kcorev1.RestartPolicyNever)
81+
knownPod2 = createPod("test-pod-2", testNamespaceTwo, kcorev1.RestartPolicyAlways)
82+
knownPod3 = createPod("test-pod-3", testNamespaceTwo, kcorev1.RestartPolicyOnFailure)
8083

8184
By("creating the informer cache")
8285
var err error
@@ -135,7 +138,7 @@ var _ = Describe("Informer Cache", func() {
135138
By("listing pods with a particular label")
136139
// NB: each pod has a "test-label" equal to the pod name
137140
out := kcorev1.PodList{}
138-
Expect(informerCache.List(context.TODO(), client.InNamespace("test-namespace-2").
141+
Expect(informerCache.List(context.TODO(), client.InNamespace(testNamespaceTwo).
139142
MatchingLabels(map[string]string{"test-label": "test-pod-2"}), &out)).NotTo(HaveOccurred())
140143

141144
By("verifying the returned pods have the correct label")
@@ -150,21 +153,21 @@ var _ = Describe("Informer Cache", func() {
150153
By("listing pods in test-namespace-1")
151154
listObj := &kcorev1.PodList{}
152155
Expect(informerCache.List(context.Background(),
153-
client.InNamespace("test-namespace-1"),
156+
client.InNamespace(testNamespaceOne),
154157
listObj)).NotTo(HaveOccurred())
155158

156159
By("verifying that the returned pods are in test-namespace-1")
157160
Expect(listObj.Items).NotTo(BeEmpty())
158161
Expect(len(listObj.Items)).To(Equal(1))
159162
actual := listObj.Items[0]
160-
Expect(actual.Namespace).To(Equal("test-namespace-1"))
163+
Expect(actual.Namespace).To(Equal(testNamespaceOne))
161164
close(done)
162165
})
163166

164167
It("should deep copy the object unless told otherwise", func(done Done) {
165168
By("retrieving a specific pod from the cache")
166169
out := &kcorev1.Pod{}
167-
podKey := client.ObjectKey{Name: "test-pod-2", Namespace: "test-namespace-2"}
170+
podKey := client.ObjectKey{Name: "test-pod-2", Namespace: testNamespaceTwo}
168171
Expect(informerCache.Get(context.Background(), podKey, out)).NotTo(HaveOccurred())
169172

170173
By("verifying the retrieved pod is equal to a known pod")

pkg/cache/informer_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
_ Cache = &informerCache{}
3838
)
3939

40-
// informerCache is a Kubernetes Object cache populated from InformersMap. cache wraps an InformersMap.
40+
// informerCache is a Kubernetes Object cache populated from InformersMap. informerCache wraps an InformersMap.
4141
type informerCache struct {
4242
*internal.InformersMap
4343
}

pkg/envtest/server.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ const (
3434
StopTimeout = 60
3535
)
3636

37+
// APIServerDefaultArgs are flags necessary to bring up apiserver.
38+
// TODO: create test framework interface to append flag to default flags.
39+
var defaultKubeAPIServerFlags = []string{
40+
"--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}",
41+
"--cert-dir={{ .CertDir }}",
42+
"--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}",
43+
"--insecure-bind-address={{ if .URL }}{{ .URL.Hostname }}{{ end }}",
44+
"--secure-port=0",
45+
"--admission-control=AlwaysAdmit",
46+
}
47+
3748
// Environment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and
3849
// install extension APIs
3950
type Environment struct {
@@ -58,8 +69,9 @@ func (te *Environment) Stop() error {
5869
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
5970
func (te *Environment) Start() (*rest.Config, error) {
6071
te.ControlPlane = integration.ControlPlane{}
72+
te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags}
6173
if os.Getenv(envKubeAPIServerBin) == "" {
62-
te.ControlPlane.APIServer = &integration.APIServer{Path: defaultKubeAPIServerBin}
74+
te.ControlPlane.APIServer.Path = defaultKubeAPIServerBin
6375
}
6476
if os.Getenv(envEtcdBin) == "" {
6577
te.ControlPlane.Etcd = &integration.Etcd{Path: defaultEtcdBin}

0 commit comments

Comments
 (0)