Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/controller/operators/olm/apiservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (a *Operator) getWebhookCABundle(csv *v1alpha1.ClusterServiceVersion, desc
return nil, fmt.Errorf("could not retrieve generated MutatingWebhookConfiguration: %v", err)
}

if len(existingWebhooks.Items) > 0 {
if len(existingWebhooks.Items) > 0 && len(existingWebhooks.Items[0].Webhooks) > 0 {
return existingWebhooks.Items[0].Webhooks[0].ClientConfig.CABundle, nil
}
case v1alpha1.ValidatingAdmissionWebhook:
Expand All @@ -410,7 +410,7 @@ func (a *Operator) getWebhookCABundle(csv *v1alpha1.ClusterServiceVersion, desc
return nil, fmt.Errorf("could not retrieve generated ValidatingWebhookConfiguration: %v", err)
}

if len(existingWebhooks.Items) > 0 {
if len(existingWebhooks.Items) > 0 && len(existingWebhooks.Items[0].Webhooks) > 0 {
return existingWebhooks.Items[0].Webhooks[0].ClientConfig.CABundle, nil
}
case v1alpha1.ConversionWebhook:
Expand Down
111 changes: 111 additions & 0 deletions pkg/controller/operators/olm/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3800,6 +3800,117 @@ func TestWebhookCABundleRetrieval(t *testing.T) {
err: nil,
},
},
{
name: "MissingMutatingCAResource",
initial: initial{
csvs: []*v1alpha1.ClusterServiceVersion{
csv("csv1",
namespace,
"0.0.0",
"",
installStrategy("csv1-dep1",
nil,
[]v1alpha1.StrategyDeploymentPermissions{},
),
[]*apiextensionsv1.CustomResourceDefinition{crd("c1", "v1", "g1")},
[]*apiextensionsv1.CustomResourceDefinition{},
v1alpha1.CSVPhaseInstalling,
),
},
desc: v1alpha1.WebhookDescription{
GenerateName: "webhook",
Type: v1alpha1.MutatingAdmissionWebhook,
},
},
expected: expected{
caBundle: nil,
err: missingCAError,
},
},
{
name: "FailFromValidatingAdmissionWebhookWithNoWebhooks",
initial: initial{
csvs: []*v1alpha1.ClusterServiceVersion{
csvWithValidatingAdmissionWebhook(csv("csv1",
namespace,
"0.0.0",
"",
installStrategy("csv1-dep1",
nil,
[]v1alpha1.StrategyDeploymentPermissions{},
),
[]*apiextensionsv1.CustomResourceDefinition{crd("c1", "v1", "g1")},
[]*apiextensionsv1.CustomResourceDefinition{},
v1alpha1.CSVPhaseInstalling,
), "csv1-dep1", []string{"c1.g1"}),
},
objs: []runtime.Object{
&admissionregistrationv1.ValidatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "webhook",
Namespace: namespace,
Labels: map[string]string{
"olm.owner": "csv1",
"olm.owner.namespace": namespace,
"olm.owner.kind": v1alpha1.ClusterServiceVersionKind,
"olm.webhook-description-generate-name": "webhook",
},
},
Webhooks: []admissionregistrationv1.ValidatingWebhook{},
},
},
desc: v1alpha1.WebhookDescription{
GenerateName: "webhook",
Type: v1alpha1.ValidatingAdmissionWebhook,
},
},
expected: expected{
caBundle: nil,
err: missingCAError,
},
},
{
name: "FailFromMutatingAdmissionWebhookWithNoWebhooks",
initial: initial{
csvs: []*v1alpha1.ClusterServiceVersion{
csvWithMutatingAdmissionWebhook(csv("csv1",
namespace,
"0.0.0",
"",
installStrategy("csv1-dep1",
nil,
[]v1alpha1.StrategyDeploymentPermissions{},
),
[]*apiextensionsv1.CustomResourceDefinition{crd("c1", "v1", "g1")},
[]*apiextensionsv1.CustomResourceDefinition{},
v1alpha1.CSVPhaseInstalling,
), "csv1-dep1", []string{"c1.g1"}),
},
objs: []runtime.Object{
&admissionregistrationv1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "webhook",
Namespace: namespace,
Labels: map[string]string{
"olm.owner": "csv1",
"olm.owner.namespace": namespace,
"olm.owner.kind": v1alpha1.ClusterServiceVersionKind,
"olm.webhook-description-generate-name": "webhook",
},
},
Webhooks: []admissionregistrationv1.MutatingWebhook{},
},
},
desc: v1alpha1.WebhookDescription{
GenerateName: "webhook",
Type: v1alpha1.MutatingAdmissionWebhook,
},
},
expected: expected{
caBundle: nil,
err: missingCAError,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down