Skip to content

Commit 5684f19

Browse files
authored
Fix issue #1668 about auto renew certificate on mutating / validating (#1669)
* fix: fix issue #1668 about auto renew certificate on mutating / validation deployment Signed-off-by: disaster37 <linuxworkgroup@hotmail.com> * fix: use the right static annotations for kubernetes and OCP. No more needed to look if cert-manager is installed. Signed-off-by: disaster37 <linuxworkgroup@hotmail.com> * fix:: use the right static annotation for kubernetes and OCP. Ne need to check if cert-manager is deployed on cluster. Signed-off-by: disaster37 <linuxworkgroup@hotmail.com> --------- Signed-off-by: disaster37 <linuxworkgroup@hotmail.com>
1 parent fc00100 commit 5684f19

5 files changed

Lines changed: 80 additions & 7 deletions

File tree

pkg/infrastructure/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2019-2025 Red Hat, Inc.
2+
// Copyright (c) 2019-2026 Red Hat, Inc.
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at

webhook/workspace/annotations.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Copyright (c) 2019-2026 Red Hat, Inc.
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
package workspace
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
22+
)
23+
24+
func getWebhookAnnotations(namespace string) map[string]string {
25+
annotations := map[string]string{}
26+
if infrastructure.IsOpenShift() {
27+
annotations["service.beta.openshift.io/inject-cabundle"] = "true"
28+
} else {
29+
annotations["cert-manager.io/inject-ca-from"] = fmt.Sprintf("%s/devworkspace-controller-serving-cert", namespace)
30+
}
31+
return annotations
32+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Copyright (c) 2019-2026 Red Hat, Inc.
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
package workspace
17+
18+
import (
19+
"testing"
20+
21+
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestGetWebhookAnnotationsWithOpenShift(t *testing.T) {
26+
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)
27+
annotations := getWebhookAnnotations("test-namespace")
28+
assert.Equal(t, map[string]string{
29+
"service.beta.openshift.io/inject-cabundle": "true",
30+
}, annotations)
31+
}
32+
33+
func TestGetWebhookAnnotationsWithKubernetes(t *testing.T) {
34+
infrastructure.InitializeForTesting(infrastructure.Kubernetes)
35+
annotations := getWebhookAnnotations("test-namespace")
36+
assert.Equal(t, map[string]string{
37+
"cert-manager.io/inject-ca-from": "test-namespace/devworkspace-controller-serving-cert",
38+
}, annotations)
39+
}

webhook/workspace/mutating_cfg.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2019-2025 Red Hat, Inc.
2+
// Copyright (c) 2019-2026 Red Hat, Inc.
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
@@ -153,8 +153,9 @@ func BuildMutateWebhookCfg(namespace string) *admregv1.MutatingWebhookConfigurat
153153

154154
return &admregv1.MutatingWebhookConfiguration{
155155
ObjectMeta: metav1.ObjectMeta{
156-
Name: MutateWebhookCfgName,
157-
Labels: server.WebhookServerAppLabels(),
156+
Name: MutateWebhookCfgName,
157+
Labels: server.WebhookServerAppLabels(),
158+
Annotations: getWebhookAnnotations(namespace),
158159
},
159160
Webhooks: []admregv1.MutatingWebhook{
160161
workspaceMutateWebhook,

webhook/workspace/validating_cfg.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2019-2025 Red Hat, Inc.
2+
// Copyright (c) 2019-2026 Red Hat, Inc.
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
@@ -34,8 +34,9 @@ func buildValidatingWebhookCfg(namespace string) *admregv1.ValidatingWebhookConf
3434
sideEffectsNone := admregv1.SideEffectClassNone
3535
return &admregv1.ValidatingWebhookConfiguration{
3636
ObjectMeta: metav1.ObjectMeta{
37-
Name: ValidateWebhookCfgName,
38-
Labels: server.WebhookServerAppLabels(),
37+
Name: ValidateWebhookCfgName,
38+
Labels: server.WebhookServerAppLabels(),
39+
Annotations: getWebhookAnnotations(namespace),
3940
},
4041
Webhooks: []admregv1.ValidatingWebhook{
4142
{

0 commit comments

Comments
 (0)