@@ -7,13 +7,15 @@ import (
7
7
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
8
8
"github.com/pkg/errors"
9
9
"github.com/sirupsen/logrus"
10
+ corev1 "k8s.io/api/core/v1"
10
11
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
11
12
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
12
13
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
13
14
apiextensionsv1beta1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
14
15
apierrors "k8s.io/apimachinery/pkg/api/errors"
15
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
17
"k8s.io/client-go/dynamic"
18
+ "k8s.io/client-go/tools/record"
17
19
"k8s.io/client-go/util/retry"
18
20
19
21
"github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -44,18 +46,20 @@ type builder struct {
44
46
dynamicClient dynamic.Interface
45
47
manifestResolver ManifestResolver
46
48
logger logrus.FieldLogger
49
+ eventRecorder record.EventRecorder
47
50
48
51
annotator alongside.Annotator
49
52
}
50
53
51
- func newBuilder (plan * v1alpha1.InstallPlan , csvLister listersv1alpha1.ClusterServiceVersionLister , opclient operatorclient.ClientInterface , dynamicClient dynamic.Interface , manifestResolver ManifestResolver , logger logrus.FieldLogger ) * builder {
54
+ func newBuilder (plan * v1alpha1.InstallPlan , csvLister listersv1alpha1.ClusterServiceVersionLister , opclient operatorclient.ClientInterface , dynamicClient dynamic.Interface , manifestResolver ManifestResolver , logger logrus.FieldLogger , er record. EventRecorder ) * builder {
52
55
return & builder {
53
56
plan : plan ,
54
57
csvLister : csvLister ,
55
58
opclient : opclient ,
56
59
dynamicClient : dynamicClient ,
57
60
manifestResolver : manifestResolver ,
58
61
logger : logger ,
62
+ eventRecorder : er ,
59
63
}
60
64
}
61
65
@@ -141,20 +145,26 @@ func (b *builder) NewCRDV1Step(client apiextensionsv1client.ApiextensionsV1Inter
141
145
crd .SetResourceVersion (currentCRD .GetResourceVersion ())
142
146
if err = validateV1CRDCompatibility (b .dynamicClient , currentCRD , crd ); err != nil {
143
147
vErr := & validationError {}
144
- // if the conversion strategy in the new CRD is "None " OR the error is not a ValidationError
148
+ // if the conversion strategy in the new CRD is not "Webhook " OR the error is not a ValidationError
145
149
// return an error. This will catch and return any errors that occur unrelated to actual validation.
146
150
// For example, the API server returning an error when performing a list operation
147
- if crd .Spec .Conversion == nil || crd .Spec .Conversion .Strategy == apiextensionsv1 .NoneConverter || ! errors .As (err , vErr ) {
151
+ if crd .Spec .Conversion == nil || crd .Spec .Conversion .Strategy != apiextensionsv1 .WebhookConverter || ! errors .As (err , vErr ) {
148
152
return fmt .Errorf ("error validating existing CRs against new CRD's schema for %q: %w" , step .Resource .Name , err )
149
153
}
150
- // If the conversion strategy in the new CRD is not "None " and the error that occurred
154
+ // If the conversion strategy in the new CRD is "Webhook " and the error that occurred
151
155
// is an error related to validation, warn that validation failed but that we are trusting
152
156
// that the conversion strategy specified by the author will successfully convert to a format
153
157
// that passes validation and allow the upgrade to continue
154
- b .logger .Warnf ("trusting conversion strategy detected in new CRD, but failed validation of existing CRs against new CRD's schema for %q: %s" ,
155
- step .Resource .Name ,
156
- err .Error (),
157
- )
158
+ warnTempl := `validation of existing CRs against new CRD's schema failed, but a webhook conversion strategy was specified.
159
+ allowing the CRD upgrade to occur as we can't run the webhook, but is assumed that it will successfully convert existing CRs
160
+ to a format that would have passed validation.
161
+
162
+ CRD: %q
163
+ Validation Error: %s
164
+ `
165
+ warnString := fmt .Sprintf (warnTempl , step .Resource .Name , err .Error ())
166
+ b .logger .Warn (warnString )
167
+ b .eventRecorder .Event (b .plan , corev1 .EventTypeWarning , "CRDValidation" , warnString )
158
168
}
159
169
160
170
// check to see if stored versions changed and whether the upgrade could cause potential data loss
0 commit comments