-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from muvaf/release-1.7-prep
Release 1.7 prep
- Loading branch information
Showing
136 changed files
with
6,144 additions
and
738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright 2022 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
"github.com/crossplane/crossplane-runtime/pkg/errors" | ||
) | ||
|
||
const ( | ||
errUnexpectedType = "unexpected type" | ||
|
||
errGroupImmutable = "spec.group is immutable" | ||
errPluralImmutable = "spec.names.plural is immutable" | ||
errKindImmutable = "spec.names.kind is immutable" | ||
errClaimPluralImmutable = "spec.claimNames.plural is immutable" | ||
errClaimKindImmutable = "spec.claimNames.kind is immutable" | ||
) | ||
|
||
// +kubebuilder:webhook:verbs=update,path=/validate-apiextensions-crossplane-io-v1-compositeresourcedefinition,mutating=false,failurePolicy=fail,groups=apiextensions.crossplane.io,resources=compositeresourcedefinitions,versions=v1,name=compositeresourcedefinitions.apiextensions.crossplane.io,sideEffects=None,admissionReviewVersions=v1 | ||
|
||
// ValidateCreate is run for creation actions. | ||
func (in *CompositeResourceDefinition) ValidateCreate() error { | ||
return nil | ||
} | ||
|
||
// ValidateUpdate is run for update actions. | ||
func (in *CompositeResourceDefinition) ValidateUpdate(old runtime.Object) error { | ||
oldObj, ok := old.(*CompositeResourceDefinition) | ||
if !ok { | ||
return errors.New(errUnexpectedType) | ||
} | ||
switch { | ||
case in.Spec.Group != oldObj.Spec.Group: | ||
return errors.New(errGroupImmutable) | ||
case in.Spec.Names.Plural != oldObj.Spec.Names.Plural: | ||
return errors.New(errPluralImmutable) | ||
case in.Spec.Names.Kind != oldObj.Spec.Names.Kind: | ||
return errors.New(errKindImmutable) | ||
} | ||
if in.Spec.ClaimNames != nil && oldObj.Spec.ClaimNames != nil { | ||
switch { | ||
case in.Spec.ClaimNames.Plural != oldObj.Spec.ClaimNames.Plural: | ||
return errors.New(errClaimPluralImmutable) | ||
case in.Spec.ClaimNames.Kind != oldObj.Spec.ClaimNames.Kind: | ||
return errors.New(errClaimKindImmutable) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// ValidateDelete is run for delete actions. | ||
func (in *CompositeResourceDefinition) ValidateDelete() error { | ||
return nil | ||
} | ||
|
||
// SetupWebhookWithManager sets up webhook with manager. | ||
func (in *CompositeResourceDefinition) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(in). | ||
Complete() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
Copyright 2022 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
"github.com/crossplane/crossplane-runtime/pkg/errors" | ||
"github.com/crossplane/crossplane-runtime/pkg/test" | ||
) | ||
|
||
func TestValidateUpdate(t *testing.T) { | ||
type args struct { | ||
old runtime.Object | ||
new *CompositeResourceDefinition | ||
} | ||
cases := map[string]struct { | ||
args | ||
err error | ||
}{ | ||
"UnexpectedType": { | ||
args: args{ | ||
old: &extv1.CustomResourceDefinition{}, | ||
new: &CompositeResourceDefinition{}, | ||
}, | ||
err: errors.New(errUnexpectedType), | ||
}, | ||
"GroupChanged": { | ||
args: args{ | ||
old: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Group: "a", | ||
}, | ||
}, | ||
new: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Group: "b", | ||
}, | ||
}, | ||
}, | ||
err: errors.New(errGroupImmutable), | ||
}, | ||
"PluralChanged": { | ||
args: args{ | ||
old: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Names: extv1.CustomResourceDefinitionNames{ | ||
Plural: "b", | ||
}, | ||
}, | ||
}, | ||
new: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Names: extv1.CustomResourceDefinitionNames{ | ||
Plural: "a", | ||
}, | ||
}, | ||
}, | ||
}, | ||
err: errors.New(errPluralImmutable), | ||
}, | ||
"KindChanged": { | ||
args: args{ | ||
old: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Names: extv1.CustomResourceDefinitionNames{ | ||
Kind: "b", | ||
}, | ||
}, | ||
}, | ||
new: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Names: extv1.CustomResourceDefinitionNames{ | ||
Kind: "a", | ||
}, | ||
}, | ||
}, | ||
}, | ||
err: errors.New(errKindImmutable), | ||
}, | ||
"ClaimPluralChanged": { | ||
args: args{ | ||
old: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
ClaimNames: &extv1.CustomResourceDefinitionNames{ | ||
Plural: "b", | ||
}, | ||
}, | ||
}, | ||
new: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
ClaimNames: &extv1.CustomResourceDefinitionNames{ | ||
Plural: "a", | ||
}, | ||
}, | ||
}, | ||
}, | ||
err: errors.New(errClaimPluralImmutable), | ||
}, | ||
"ClaimKindChanged": { | ||
args: args{ | ||
old: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
ClaimNames: &extv1.CustomResourceDefinitionNames{ | ||
Kind: "b", | ||
}, | ||
}, | ||
}, | ||
new: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
ClaimNames: &extv1.CustomResourceDefinitionNames{ | ||
Kind: "a", | ||
}, | ||
}, | ||
}, | ||
}, | ||
err: errors.New(errClaimKindImmutable), | ||
}, | ||
"Success": { | ||
args: args{ | ||
old: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Names: extv1.CustomResourceDefinitionNames{ | ||
Kind: "a", | ||
}, | ||
}, | ||
}, | ||
new: &CompositeResourceDefinition{ | ||
Spec: CompositeResourceDefinitionSpec{ | ||
Names: extv1.CustomResourceDefinitionNames{ | ||
Kind: "a", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
err := tc.new.ValidateUpdate(tc.old) | ||
if diff := cmp.Diff(tc.err, err, test.EquateErrors()); diff != "" { | ||
t.Errorf("ValidateUpdate(): -want, +got:\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.