Skip to content

Commit 80ceca2

Browse files
author
Mengqi Yu
committed
fs cert writer
1 parent e8701fb commit 80ceca2

File tree

5 files changed

+279
-130
lines changed

5 files changed

+279
-130
lines changed

pkg/admission/cert/writer/certwriter.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"net/url"
2626

2727
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
28-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2928
"k8s.io/apimachinery/pkg/runtime"
3029
"sigs.k8s.io/controller-runtime/pkg/admission/cert/generator"
3130
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -66,13 +65,13 @@ func NewCertWriter(ops Options) (CertWriter, error) {
6665
Client: ops.Client,
6766
CertGenerator: ops.CertGenerator,
6867
}
69-
//f := &FSCertWriter{
70-
// CertGenerator: ops.CertGenerator,
71-
//}
68+
f := &FSCertWriter{
69+
CertGenerator: ops.CertGenerator,
70+
}
7271
return &MultiCertWriter{
7372
CertWriters: []CertWriter{
7473
s,
75-
//f,
74+
f,
7675
},
7776
}, nil
7877
}
@@ -113,12 +112,12 @@ func handleCommon(webhook *admissionregistrationv1beta1.Webhook, ch certReadWrit
113112
func createIfNotExists(webhookName string, ch certReadWriter) (*generator.Artifacts, error) {
114113
// Try to read first
115114
certs, err := ch.read(webhookName)
116-
if apierrors.IsNotFound(err) {
115+
if isNotFound(err) {
117116
// Create if not exists
118117
certs, err = ch.write(webhookName)
119118
switch {
120119
// This may happen if there is another racer.
121-
case apierrors.IsAlreadyExists(err):
120+
case isAlreadyExists(err):
122121
certs, err = ch.read(webhookName)
123122
if err != nil {
124123
return certs, err

pkg/admission/cert/writer/certwriter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ = Describe("NewProvider", func() {
5757
Client: cl,
5858
CertGenerator: &generator.SelfSignedCertGenerator{},
5959
},
60-
//&FSCertWriterProvider{
60+
//&FSCertWriter{
6161
// CertGenerator: &certgenerator.SelfSignedCertGenerator{},
6262
//},
6363
},

pkg/admission/cert/writer/error.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package writer
18+
19+
type notFoundError struct {
20+
err error
21+
}
22+
23+
func (e notFoundError) Error() string {
24+
return e.err.Error()
25+
}
26+
27+
func isNotFound(err error) bool {
28+
_, ok := err.(notFoundError)
29+
return ok
30+
}
31+
32+
type alreadyExistError struct {
33+
err error
34+
}
35+
36+
func (e alreadyExistError) Error() string {
37+
return e.err.Error()
38+
}
39+
40+
func isAlreadyExists(err error) bool {
41+
_, ok := err.(alreadyExistError)
42+
return ok
43+
}

0 commit comments

Comments
 (0)