Skip to content

Commit 654ed3f

Browse files
authored
Merge pull request openshift#36 from awgreene/webhook-desc-container-port
WebhookDesc should use containerPort field
2 parents 7856a40 + 2cd1a84 commit 654ed3f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

pkg/operators/v1alpha1/clusterserviceversion_test.go

+55
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89

910
"github.com/stretchr/testify/assert"
@@ -358,6 +359,60 @@ func TestSetPhaseWithConditions(t *testing.T) {
358359
}
359360
}
360361

362+
func TestWebhookDescGetValidatingConfigurations(t *testing.T) {
363+
expectedPort := int32(444)
364+
timeout := int32(32)
365+
webhookPath := "/test"
366+
failurePolicy := admissionregistrationv1.Fail
367+
matchPolicy := admissionregistrationv1.Exact
368+
sideEffect := admissionregistrationv1.SideEffectClassNone
369+
webhookDesc := WebhookDescription{
370+
GenerateName: "foo-webhook",
371+
Type: ValidatingAdmissionWebhook,
372+
DeploymentName: "foo-deployment",
373+
ContainerPort: expectedPort,
374+
AdmissionReviewVersions: []string{"v1beta1", "v1"},
375+
SideEffects: &sideEffect,
376+
MatchPolicy: &matchPolicy,
377+
FailurePolicy: &failurePolicy,
378+
ObjectSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
379+
TimeoutSeconds: &timeout,
380+
WebhookPath: &webhookPath,
381+
Rules: []admissionregistrationv1.RuleWithOperations{
382+
admissionregistrationv1.RuleWithOperations{
383+
Operations: []admissionregistrationv1.OperationType{},
384+
Rule: admissionregistrationv1.Rule{
385+
APIGroups: []string{"*"},
386+
APIVersions: []string{"*"},
387+
Resources: []string{"*"},
388+
},
389+
},
390+
},
391+
}
392+
vWebhookConfig := webhookDesc.GetValidatingWebhook("foo", nil, nil)
393+
require.Equal(t, expectedPort, *vWebhookConfig.ClientConfig.Service.Port)
394+
require.Equal(t, webhookDesc.Rules, vWebhookConfig.Rules)
395+
require.Equal(t, webhookDesc.FailurePolicy, vWebhookConfig.FailurePolicy)
396+
require.Equal(t, webhookDesc.MatchPolicy, vWebhookConfig.MatchPolicy)
397+
require.Equal(t, webhookDesc.ObjectSelector, vWebhookConfig.ObjectSelector)
398+
require.Equal(t, webhookDesc.SideEffects, vWebhookConfig.SideEffects)
399+
require.Equal(t, webhookDesc.TimeoutSeconds, vWebhookConfig.TimeoutSeconds)
400+
require.Equal(t, webhookDesc.AdmissionReviewVersions, vWebhookConfig.AdmissionReviewVersions)
401+
require.Equal(t, webhookDesc.WebhookPath, vWebhookConfig.ClientConfig.Service.Path)
402+
403+
mWebhookConfig := webhookDesc.GetMutatingWebhook("foo", nil, nil)
404+
require.Equal(t, expectedPort, *mWebhookConfig.ClientConfig.Service.Port)
405+
require.Equal(t, webhookDesc.Rules, mWebhookConfig.Rules)
406+
require.Equal(t, webhookDesc.FailurePolicy, mWebhookConfig.FailurePolicy)
407+
require.Equal(t, webhookDesc.MatchPolicy, mWebhookConfig.MatchPolicy)
408+
require.Equal(t, webhookDesc.ObjectSelector, mWebhookConfig.ObjectSelector)
409+
require.Equal(t, webhookDesc.SideEffects, mWebhookConfig.SideEffects)
410+
require.Equal(t, webhookDesc.TimeoutSeconds, mWebhookConfig.TimeoutSeconds)
411+
require.Equal(t, webhookDesc.AdmissionReviewVersions, mWebhookConfig.AdmissionReviewVersions)
412+
require.Equal(t, webhookDesc.ReinvocationPolicy, mWebhookConfig.ReinvocationPolicy)
413+
require.Equal(t, webhookDesc.WebhookPath, mWebhookConfig.ClientConfig.Service.Path)
414+
}
415+
361416
func helperNewConditions(count int) []ClusterServiceVersionCondition {
362417
conditions := make([]ClusterServiceVersionCondition, 0)
363418

pkg/operators/v1alpha1/clusterserviceversion_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (w *WebhookDescription) GetValidatingWebhook(namespace string, namespaceSel
197197
Name: w.DomainName() + "-service",
198198
Namespace: namespace,
199199
Path: w.WebhookPath,
200+
Port: &w.ContainerPort,
200201
},
201202
CABundle: caBundle,
202203
},
@@ -220,6 +221,7 @@ func (w *WebhookDescription) GetMutatingWebhook(namespace string, namespaceSelec
220221
Name: w.DomainName() + "-service",
221222
Namespace: namespace,
222223
Path: w.WebhookPath,
224+
Port: &w.ContainerPort,
223225
},
224226
CABundle: caBundle,
225227
},

0 commit comments

Comments
 (0)