Skip to content

Commit

Permalink
Merge pull request #38 from muvaf/release-1.7-prep
Browse files Browse the repository at this point in the history
Release 1.7 prep
  • Loading branch information
muvaf authored Apr 19, 2022
2 parents d2e979d + 3290eb8 commit 5cbc836
Show file tree
Hide file tree
Showing 136 changed files with 6,144 additions and 738 deletions.
14 changes: 14 additions & 0 deletions apis/apiextensions/v1/composition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// CompositionSpec specifies desired state of a composition.
Expand All @@ -42,8 +44,20 @@ type CompositionSpec struct {
// WriteConnectionSecretsToNamespace specifies the namespace in which the
// connection secrets of composite resource dynamically provisioned using
// this composition will be created.
// This field is planned to be replaced in a future release in favor of
// PublishConnectionDetailsWithStoreConfigRef. Currently, both could be
// set independently and connection details would be published to both
// without affecting each other as long as related fields at MR level
// specified.
// +optional
WriteConnectionSecretsToNamespace *string `json:"writeConnectionSecretsToNamespace,omitempty"`

// PublishConnectionDetailsWithStoreConfig specifies the secret store config
// with which the connection secrets of composite resource dynamically
// provisioned using this composition will be published.
// +optional
// +kubebuilder:default={"name": "default"}
PublishConnectionDetailsWithStoreConfigRef *xpv1.Reference `json:"publishConnectionDetailsWithStoreConfigRef,omitempty"`
}

// A PatchSet is a set of patches that can be reused from all resources within
Expand Down
13 changes: 13 additions & 0 deletions apis/apiextensions/v1/xrd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ type CompositeResourceDefinitionSpec struct {
// Group specifies the API group of the defined composite resource.
// Composite resources are served under `/apis/<group>/...`. Must match the
// name of the XRD (in the form `<names.plural>.<group>`).
// +immutable
Group string `json:"group"`

// Names specifies the resource and kind names of the defined composite
// resource.
// +immutable
Names extv1.CustomResourceDefinitionNames `json:"names"`

// ClaimNames specifies the names of an optional composite resource claim.
Expand All @@ -45,6 +47,7 @@ type CompositeResourceDefinitionSpec struct {
// create, update, or delete a corresponding composite resource. You may add
// claim names to an existing CompositeResourceDefinition, but they cannot
// be changed or removed once they have been set.
// +immutable
// +optional
ClaimNames *extv1.CustomResourceDefinitionNames `json:"claimNames,omitempty"`

Expand Down Expand Up @@ -98,6 +101,16 @@ type CompositeResourceDefinitionVersion struct {
// Served specifies that this version should be served via REST APIs.
Served bool `json:"served"`

// The deprecated field specifies that this version is deprecated and should
// not be used.
// +optional
Deprecated *bool `json:"deprecated,omitempty"`

// DeprecationWarning specifies the message that should be shown to the user
// when using this version.
// +optional
DeprecationWarning *string `json:"deprecationWarning,omitempty"`

// Schema describes the schema used for validation, pruning, and defaulting
// of this version of the defined composite resource. Fields required by all
// composite resources will be injected into this schema automatically, and
Expand Down
78 changes: 78 additions & 0 deletions apis/apiextensions/v1/xrd_webhooks.go
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()
}
165 changes: 165 additions & 0 deletions apis/apiextensions/v1/xrd_webhooks_test.go
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)
}
})
}
}
15 changes: 15 additions & 0 deletions apis/apiextensions/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions apis/apiextensions/v1alpha1/revision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,21 @@ type CompositionRevisionSpec struct {
// WriteConnectionSecretsToNamespace specifies the namespace in which the
// connection secrets of composite resource dynamically provisioned using
// this composition will be created.
// This field is planned to be removed in a future release in favor of
// PublishConnectionDetailsWithStoreConfigRef. Currently, both could be
// set independently and connection details would be published to both
// without affecting each other as long as related fields at MR level
// specified.
// +optional
WriteConnectionSecretsToNamespace *string `json:"writeConnectionSecretsToNamespace,omitempty"`

// PublishConnectionDetailsWithStoreConfig specifies the secret store config
// with which the connection secrets of composite resource dynamically
// provisioned using this composition will be published.
// +optional
// +kubebuilder:default={"name": "default"}
PublishConnectionDetailsWithStoreConfigRef *xpv1.Reference `json:"publishConnectionDetailsWithStoreConfigRef,omitempty"`

// Revision number. Newer revisions have larger numbers.
// +immutable
Revision int64 `json:"revision"`
Expand Down
6 changes: 6 additions & 0 deletions apis/apiextensions/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (

"github.com/crossplane/crossplane/apis/apiextensions"
"github.com/crossplane/crossplane/apis/pkg"
"github.com/crossplane/crossplane/apis/secrets"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes,
apiextensions.AddToScheme,
pkg.AddToScheme,
secrets.AddToScheme,
)
}

Expand Down
Loading

0 comments on commit 5cbc836

Please sign in to comment.