From 4bbcdd006293cc8b9e24ceade7f76b2aca59b911 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Fri, 18 Aug 2023 08:43:44 +1200 Subject: [PATCH] chore: remove v1alpha1 domainmapping the API is deprecated and is ready to removed --- cmd/webhook/main.go | 4 +- config/core/300-resources/domain-mapping.yaml | 116 ----- docs/serving-api.md | 261 +---------- hack/update-codegen.sh | 4 +- .../v1alpha1/domainmapping_defaults.go | 36 -- .../v1alpha1/domainmapping_defaults_test.go | 187 -------- .../v1alpha1/domainmapping_lifecycle.go | 180 ------- .../v1alpha1/domainmapping_lifecycle_test.go | 337 -------------- .../serving/v1alpha1/domainmapping_types.go | 135 ------ .../v1alpha1/domainmapping_types_test.go | 37 -- .../v1alpha1/domainmapping_validation.go | 73 --- .../v1alpha1/domainmapping_validation_test.go | 287 ------------ pkg/apis/serving/v1alpha1/register.go | 8 +- pkg/apis/serving/v1alpha1/register_test.go | 3 - .../serving/v1alpha1/zz_generated.deepcopy.go | 132 ------ .../typed/serving/v1alpha1/domainmapping.go | 195 -------- .../v1alpha1/fake/fake_domainmapping.go | 142 ------ .../v1alpha1/fake/fake_serving_client.go | 5 - .../serving/v1alpha1/generated_expansion.go | 2 - .../typed/serving/v1alpha1/serving_client.go | 5 - .../informers/externalversions/generic.go | 5 - .../externalversions/serving/interface.go | 8 - .../serving/v1alpha1/domainmapping.go | 90 ---- .../serving/v1alpha1/interface.go | 45 -- .../v1alpha1/domainmapping/domainmapping.go | 52 --- .../v1alpha1/domainmapping/fake/fake.go | 40 -- .../domainmapping/filtered/domainmapping.go | 65 --- .../domainmapping/filtered/fake/fake.go | 52 --- .../v1alpha1/domainmapping/controller.go | 170 ------- .../v1alpha1/domainmapping/reconciler.go | 440 ------------------ .../serving/v1alpha1/domainmapping/state.go | 97 ---- .../listers/serving/v1alpha1/domainmapping.go | 99 ---- .../serving/v1alpha1/expansion_generated.go | 27 -- pkg/reconciler/domainmapping/controller.go | 8 +- pkg/reconciler/domainmapping/reconciler.go | 22 +- .../domainmapping/resources/certificate.go | 4 +- .../resources/certificate_test.go | 12 +- .../domainmapping/resources/domainclaim.go | 4 +- .../resources/domainclaim_test.go | 4 +- .../domainmapping/resources/ingress.go | 4 +- .../domainmapping/resources/ingress_test.go | 16 +- pkg/reconciler/domainmapping/table_test.go | 71 +-- pkg/reconciler/testing/v1/listers.go | 8 +- pkg/testing/v1alpha1/domainmapping.go | 47 -- test/clients.go | 37 +- .../api/v1alpha1/domain_mapping_test.go | 226 --------- .../api/v1beta1/domain_mapping_test.go | 8 +- test/e2e/autotls/domain_mapping_test.go | 12 +- test/e2e/domainmapping/domain_mapping_test.go | 15 +- .../k8s.io/code-generator/generate-groups.sh | 0 .../knative.dev/pkg/hack/generate-knative.sh | 0 51 files changed, 106 insertions(+), 3731 deletions(-) delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_defaults.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_defaults_test.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_lifecycle.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_lifecycle_test.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_types.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_types_test.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_validation.go delete mode 100644 pkg/apis/serving/v1alpha1/domainmapping_validation_test.go delete mode 100644 pkg/client/clientset/versioned/typed/serving/v1alpha1/domainmapping.go delete mode 100644 pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_domainmapping.go delete mode 100644 pkg/client/informers/externalversions/serving/v1alpha1/domainmapping.go delete mode 100644 pkg/client/informers/externalversions/serving/v1alpha1/interface.go delete mode 100644 pkg/client/injection/informers/serving/v1alpha1/domainmapping/domainmapping.go delete mode 100644 pkg/client/injection/informers/serving/v1alpha1/domainmapping/fake/fake.go delete mode 100644 pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/domainmapping.go delete mode 100644 pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/fake/fake.go delete mode 100644 pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/controller.go delete mode 100644 pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/reconciler.go delete mode 100644 pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/state.go delete mode 100644 pkg/client/listers/serving/v1alpha1/domainmapping.go delete mode 100644 pkg/client/listers/serving/v1alpha1/expansion_generated.go delete mode 100644 pkg/testing/v1alpha1/domainmapping.go delete mode 100644 test/conformance/api/v1alpha1/domain_mapping_test.go mode change 100644 => 100755 vendor/k8s.io/code-generator/generate-groups.sh mode change 100644 => 100755 vendor/knative.dev/pkg/hack/generate-knative.sh diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 9b87572645b0..ed315bef43f9 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -33,7 +33,6 @@ import ( "knative.dev/pkg/webhook/resourcesemantics" "knative.dev/pkg/webhook/resourcesemantics/defaulting" "knative.dev/pkg/webhook/resourcesemantics/validation" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" servingv1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1" // resource validation types @@ -66,8 +65,7 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ net.SchemeGroupVersion.WithKind("Ingress"): &net.Ingress{}, net.SchemeGroupVersion.WithKind("ServerlessService"): &net.ServerlessService{}, - servingv1alpha1.SchemeGroupVersion.WithKind("DomainMapping"): &servingv1alpha1.DomainMapping{}, - servingv1beta1.SchemeGroupVersion.WithKind("DomainMapping"): &servingv1beta1.DomainMapping{}, + servingv1beta1.SchemeGroupVersion.WithKind("DomainMapping"): &servingv1beta1.DomainMapping{}, } var serviceValidation = validation.NewCallback( diff --git a/config/core/300-resources/domain-mapping.yaml b/config/core/300-resources/domain-mapping.yaml index 8ea083587da3..b11e939e6767 100644 --- a/config/core/300-resources/domain-mapping.yaml +++ b/config/core/300-resources/domain-mapping.yaml @@ -147,122 +147,6 @@ spec: url: description: URL is the URL of this DomainMapping. type: string - - name: v1alpha1 - served: true - storage: false - deprecated: true - deprecationWarning: The v1alpha1 version of DomainMapping has been deprecated and will be removed in a future release of the API. Please upgrade to v1beta1 - subresources: - status: {} - schema: - openAPIV3Schema: - description: DomainMapping is a mapping from a custom hostname to an Addressable. - type: object - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: 'Spec is the desired state of the DomainMapping. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status' - type: object - required: - - ref - properties: - ref: - description: "Ref specifies the target of the Domain Mapping. \n The object identified by the Ref must be an Addressable with a URL of the form `{name}.{namespace}.{domain}` where `{domain}` is the cluster domain, and `{name}` and `{namespace}` are the name and namespace of a Kubernetes Service. \n This contract is satisfied by Knative types such as Knative Services and Knative Routes, and by Kubernetes Services." - type: object - required: - - kind - - name - properties: - address: - description: Address points to a specific Address Name. - type: string - apiVersion: - description: API version of the referent. - type: string - group: - description: 'Group of the API, without the version of the group. This can be used as an alternative to the APIVersion, and then resolved using ResolveGroup. Note: This API is EXPERIMENTAL and might break anytime. For more details: https://github.com/knative/eventing/issues/5086' - type: string - kind: - description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' - type: string - namespace: - description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ This is optional field, it gets defaulted to the object holding it if left out.' - type: string - tls: - description: TLS allows the DomainMapping to terminate TLS traffic with an existing secret. - type: object - required: - - secretName - properties: - secretName: - description: SecretName is the name of the existing secret used to terminate TLS traffic. - type: string - status: - description: 'Status is the current state of the DomainMapping. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status' - type: object - properties: - address: - description: Address holds the information needed for a DomainMapping to be the target of an event. - type: object - properties: - CACerts: - description: CACerts is the Certification Authority (CA) certificates in PEM format according to https://www.rfc-editor.org/rfc/rfc7468. - type: string - name: - description: Name is the name of the address. - type: string - url: - type: string - annotations: - description: Annotations is additional Status fields for the Resource to save some additional State as well as convey more information to the user. This is roughly akin to Annotations on any k8s resource, just the reconciler conveying richer information outwards. - type: object - additionalProperties: - type: string - conditions: - description: Conditions the latest available observations of a resource's current state. - type: array - items: - description: 'Condition defines a readiness condition for a Knative resource. See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties' - type: object - required: - - status - - type - properties: - lastTransitionTime: - description: LastTransitionTime is the last time the condition transitioned from one status to another. We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic differences (all other things held constant). - type: string - message: - description: A human readable message indicating details about the transition. - type: string - reason: - description: The reason for the condition's last transition. - type: string - severity: - description: Severity with which to treat failures of this type of condition. When this is not specified, it defaults to Error. - type: string - status: - description: Status of the condition, one of True, False, Unknown. - type: string - type: - description: Type of condition. - type: string - observedGeneration: - description: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller. - type: integer - format: int64 - url: - description: URL is the URL of this DomainMapping. - type: string additionalPrinterColumns: - name: URL type: string diff --git a/docs/serving-api.md b/docs/serving-api.md index 26290a849fe6..a4f2bcaf37f9 100644 --- a/docs/serving-api.md +++ b/docs/serving-api.md @@ -2093,125 +2093,7 @@ backward compatibility by support multiple concurrent versions of the same resource

Resource Types: - -

DomainMapping -

-
-

DomainMapping is a mapping from a custom hostname to an Addressable.

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FieldDescription
-apiVersion
-string
- -serving.knative.dev/v1alpha1 - -
-kind
-string -
DomainMapping
-metadata
- - -Kubernetes meta/v1.ObjectMeta - - -
-(Optional) -

Standard object’s metadata. -More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata

-Refer to the Kubernetes API documentation for the fields of the -metadata field. -
-spec
- - -DomainMappingSpec - - -
-(Optional) -

Spec is the desired state of the DomainMapping. -More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

-
-
- - - - - - - - - -
-ref
- - -knative.dev/pkg/apis/duck/v1.KReference - - -
-

Ref specifies the target of the Domain Mapping.

-

The object identified by the Ref must be an Addressable with a URL of the -form {name}.{namespace}.{domain} where {domain} is the cluster domain, -and {name} and {namespace} are the name and namespace of a Kubernetes -Service.

-

This contract is satisfied by Knative types such as Knative Services and -Knative Routes, and by Kubernetes Services.

-
-tls
- - -SecretTLS - - -
-(Optional) -

TLS allows the DomainMapping to terminate TLS traffic with an existing secret.

-
-
-status
- - -DomainMappingStatus - - -
-(Optional) -

Status is the current state of the DomainMapping. -More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

-
+

CannotConvertError

@@ -2247,147 +2129,6 @@ string -

DomainMappingSpec -

-

-(Appears on:DomainMapping) -

-
-

DomainMappingSpec describes the DomainMapping the user wishes to exist.

-
- - - - - - - - - - - - - - - - - -
FieldDescription
-ref
- - -knative.dev/pkg/apis/duck/v1.KReference - - -
-

Ref specifies the target of the Domain Mapping.

-

The object identified by the Ref must be an Addressable with a URL of the -form {name}.{namespace}.{domain} where {domain} is the cluster domain, -and {name} and {namespace} are the name and namespace of a Kubernetes -Service.

-

This contract is satisfied by Knative types such as Knative Services and -Knative Routes, and by Kubernetes Services.

-
-tls
- - -SecretTLS - - -
-(Optional) -

TLS allows the DomainMapping to terminate TLS traffic with an existing secret.

-
-

DomainMappingStatus -

-

-(Appears on:DomainMapping) -

-
-

DomainMappingStatus describes the current state of the DomainMapping.

-
- - - - - - - - - - - - - - - - - - - - - -
FieldDescription
-Status
- - -knative.dev/pkg/apis/duck/v1.Status - - -
-

-(Members of Status are embedded into this type.) -

-
-url
- - -knative.dev/pkg/apis.URL - - -
-(Optional) -

URL is the URL of this DomainMapping.

-
-address
- - -knative.dev/pkg/apis/duck/v1.Addressable - - -
-(Optional) -

Address holds the information needed for a DomainMapping to be the target of an event.

-
-

SecretTLS -

-

-(Appears on:DomainMappingSpec) -

-
-

SecretTLS wrapper for TLS SecretName.

-
- - - - - - - - - - - - - -
FieldDescription
-secretName
- -string - -
-

SecretName is the name of the existing secret used to terminate TLS traffic.

-

serving.knative.dev/v1beta1

diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 0f6f8a07a6f4..e1d17c06524d 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -66,7 +66,7 @@ group "Kubernetes Codegen" # instead of the $GOPATH directly. For normal projects this can be dropped. ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ knative.dev/serving/pkg/client knative.dev/serving/pkg/apis \ - "serving:v1 serving:v1beta1 serving:v1alpha1 autoscaling:v1alpha1" \ + "serving:v1 serving:v1beta1 autoscaling:v1alpha1" \ --go-header-file "${boilerplate}" group "Knative Codegen" @@ -74,7 +74,7 @@ group "Knative Codegen" # Knative Injection ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \ knative.dev/serving/pkg/client knative.dev/serving/pkg/apis \ - "serving:v1 serving:v1beta1 serving:v1alpha1 autoscaling:v1alpha1" \ + "serving:v1 serving:v1beta1 autoscaling:v1alpha1" \ --go-header-file "${boilerplate}" group "Deepcopy Gen" diff --git a/pkg/apis/serving/v1alpha1/domainmapping_defaults.go b/pkg/apis/serving/v1alpha1/domainmapping_defaults.go deleted file mode 100644 index 98db9daba6b0..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_defaults.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "context" - - "knative.dev/pkg/apis" - "knative.dev/serving/pkg/apis/serving" -) - -// SetDefaults implements apis.Defaultable. -func (dm *DomainMapping) SetDefaults(ctx context.Context) { - ctx = apis.WithinParent(ctx, dm.ObjectMeta) - dm.Spec.Ref.SetDefaults(apis.WithinSpec(ctx)) - - if apis.IsInUpdate(ctx) { - serving.SetUserInfo(ctx, apis.GetBaseline(ctx).(*DomainMapping).Spec, dm.Spec, dm) - } else { - serving.SetUserInfo(ctx, nil, dm.Spec, dm) - } -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_defaults_test.go b/pkg/apis/serving/v1alpha1/domainmapping_defaults_test.go deleted file mode 100644 index 8e99c550217c..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_defaults_test.go +++ /dev/null @@ -1,187 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - authv1 "k8s.io/api/authentication/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/serving/pkg/apis/serving" -) - -func TestDomainMappingDefaulting(t *testing.T) { - tests := []struct { - name string - in, out *DomainMapping - }{{ - name: "empty", - in: &DomainMapping{}, - out: &DomainMapping{}, - }, { - name: "empty ref namespace", - in: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "some-namespace", - }, - }, - out: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "some-namespace", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Namespace: "some-namespace", - }, - }, - }, - }, { - name: "explicit ref namespace", - in: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "some-namespace", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Namespace: "explicit-namespace", - }, - }, - }, - out: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "some-namespace", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Namespace: "explicit-namespace", - }, - }, - }, - }} - - for _, test := range tests { - ctx := context.Background() - - test.in.SetDefaults(ctx) - if !cmp.Equal(test.out, test.in) { - t.Errorf("SetDefaults (-want, +got):\n%s", cmp.Diff(test.out, test.in)) - } - } -} - -func TestDomainMappingUserInfo(t *testing.T) { - const ( - u1 = "oveja@knative.dev" - u2 = "cabra@knative.dev" - u3 = "vaca@knative.dev" - ) - withUserAnns := func(u1, u2 string, s *DomainMapping) *DomainMapping { - a := s.GetAnnotations() - if a == nil { - a = map[string]string{} - s.SetAnnotations(a) - } - a[serving.CreatorAnnotation] = u1 - a[serving.UpdaterAnnotation] = u2 - return s - } - tests := []struct { - name string - user string - this *DomainMapping - prev *DomainMapping - wantAnns map[string]string - }{{ - name: "create-new", - user: u1, - this: &DomainMapping{}, - prev: nil, - wantAnns: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u1, - }, - }, { - name: "update-no-diff-new-object", - user: u2, - this: withUserAnns(u1, u1, &DomainMapping{}), - prev: withUserAnns(u1, u1, &DomainMapping{}), - wantAnns: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u1, - }, - }, { - name: "update-diff-old-object", - user: u2, - this: &DomainMapping{ - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "new", - }, - }, - }, - prev: &DomainMapping{ - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "old", - }, - }, - }, - wantAnns: map[string]string{ - serving.UpdaterAnnotation: u2, - }, - }, { - name: "update-diff-new-object", - user: u3, - this: withUserAnns(u1, u2, &DomainMapping{ - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "new", - }, - }, - }), - prev: withUserAnns(u1, u2, &DomainMapping{ - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "old", - }, - }, - }), - wantAnns: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u3, - }, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - ctx := apis.WithUserInfo(context.Background(), &authv1.UserInfo{ - Username: test.user, - }) - if test.prev != nil { - ctx = apis.WithinUpdate(ctx, test.prev) - test.prev.SetDefaults(ctx) - } - test.this.SetDefaults(ctx) - if got, want := test.this.GetAnnotations(), test.wantAnns; !cmp.Equal(got, want) { - t.Errorf("Annotations = %v, want: %v, diff (-got, +want): %s", got, want, cmp.Diff(got, want)) - } - }) - } -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_lifecycle.go b/pkg/apis/serving/v1alpha1/domainmapping_lifecycle.go deleted file mode 100644 index ed189c3dd66a..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_lifecycle.go +++ /dev/null @@ -1,180 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1" - "knative.dev/pkg/apis" -) - -var domainMappingCondSet = apis.NewLivingConditionSet( - DomainMappingConditionDomainClaimed, - DomainMappingConditionReferenceResolved, - DomainMappingConditionIngressReady, - DomainMappingConditionCertificateProvisioned, -) - -// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. -func (*DomainMapping) GetConditionSet() apis.ConditionSet { - return domainMappingCondSet -} - -// GetGroupVersionKind returns the GroupVersionKind. -func (dm *DomainMapping) GetGroupVersionKind() schema.GroupVersionKind { - return SchemeGroupVersion.WithKind("DomainMapping") -} - -// IsReady returns true if the DomainMapping is ready. -func (dms *DomainMappingStatus) IsReady() bool { - return domainMappingCondSet.Manage(dms).IsHappy() -} - -// IsReady returns true if the Status condition DomainMappingConditionReady -// is true and the latest spec has been observed. -func (dm *DomainMapping) IsReady() bool { - dms := dm.Status - return dms.ObservedGeneration == dm.Generation && - dms.GetCondition(DomainMappingConditionReady).IsTrue() -} - -// InitializeConditions sets the initial values to the conditions. -func (dms *DomainMappingStatus) InitializeConditions() { - domainMappingCondSet.Manage(dms).InitializeConditions() -} - -const ( - // AutoTLSNotEnabledMessage is the message which is set on the - // DomainMappingConditionCertificateProvisioned condition when it is set to True - // because AutoTLS was not enabled. - AutoTLSNotEnabledMessage = "autoTLS is not enabled" - // TLSCertificateProvidedExternally indicates that a TLS secret won't be created or managed - // instead a reference to an existing TLS secret should have been provided in the DomainMapping spec - TLSCertificateProvidedExternally = "TLS certificate was provided externally" -) - -// MarkTLSNotEnabled sets DomainMappingConditionCertificateProvisioned to true when -// certificate provisioning was skipped because TLS was not enabled. -func (dms *DomainMappingStatus) MarkTLSNotEnabled(msg string) { - domainMappingCondSet.Manage(dms).MarkTrueWithReason(DomainMappingConditionCertificateProvisioned, - "TLSNotEnabled", msg) -} - -func (dms *DomainMappingStatus) MarkCertificateNotRequired(msg string) { - domainMappingCondSet.Manage(dms).MarkTrueWithReason(DomainMappingConditionCertificateProvisioned, - "CertificateExternallyProvided", msg) -} - -// MarkCertificateReady marks the DomainMappingConditionCertificateProvisioned -// condition to indicate that the Certificate is ready. -func (dms *DomainMappingStatus) MarkCertificateReady(name string) { - domainMappingCondSet.Manage(dms).MarkTrue(DomainMappingConditionCertificateProvisioned) -} - -// MarkCertificateNotReady marks the DomainMappingConditionCertificateProvisioned -// condition to indicate that the Certificate is not ready. -func (dms *DomainMappingStatus) MarkCertificateNotReady(name string) { - domainMappingCondSet.Manage(dms).MarkUnknown(DomainMappingConditionCertificateProvisioned, - "CertificateNotReady", - "Certificate %s is not ready.", name) -} - -// MarkCertificateNotOwned changes the DomainMappingConditionCertificateProvisioned -// status to be false with the reason being that there is an existing -// certificate with the name we wanted to use. -func (dms *DomainMappingStatus) MarkCertificateNotOwned(name string) { - domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionCertificateProvisioned, - "CertificateNotOwned", - "There is an existing certificate %s that we don't own.", name) -} - -// MarkCertificateProvisionFailed marks the -// DomainMappingConditionCertificateProvisioned condition to indicate that the -// Certificate provisioning failed. -func (dms *DomainMappingStatus) MarkCertificateProvisionFailed(name string) { - domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionCertificateProvisioned, - "CertificateProvisionFailed", - "Certificate %s failed to be provisioned.", name) -} - -// MarkHTTPDowngrade sets DomainMappingConditionCertificateProvisioned to true when plain -// HTTP is enabled even when Certificate is not ready. -func (dms *DomainMappingStatus) MarkHTTPDowngrade(name string) { - domainMappingCondSet.Manage(dms).MarkTrueWithReason(DomainMappingConditionCertificateProvisioned, - "HTTPDowngrade", - "Certificate %s is not ready downgrade HTTP.", name) -} - -// MarkIngressNotConfigured changes the IngressReady condition to be unknown to reflect -// that the Ingress does not yet have a Status. -func (dms *DomainMappingStatus) MarkIngressNotConfigured() { - domainMappingCondSet.Manage(dms).MarkUnknown(DomainMappingConditionIngressReady, - "IngressNotConfigured", "Ingress has not yet been reconciled.") -} - -// MarkDomainClaimed updates the DomainMappingConditionDomainClaimed condition -// to indicate that the domain was successfully claimed. -func (dms *DomainMappingStatus) MarkDomainClaimed() { - domainMappingCondSet.Manage(dms).MarkTrue(DomainMappingConditionDomainClaimed) -} - -// MarkDomainClaimNotOwned updates the DomainMappingConditionDomainClaimed -// condition to indicate that the domain is already in use by another -// DomainMapping. -func (dms *DomainMappingStatus) MarkDomainClaimNotOwned() { - domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionDomainClaimed, "DomainAlreadyClaimed", - "The domain name is already in use by another DomainMapping") -} - -// MarkDomainClaimFailed updates the DomainMappingConditionDomainClaimed -// condition to indicate that creating the ClusterDomainClaim failed. -func (dms *DomainMappingStatus) MarkDomainClaimFailed(reason string) { - domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionDomainClaimed, "DomainClaimFailed", reason) -} - -// MarkReferenceResolved sets the DomainMappingConditionReferenceResolved -// condition to true. -func (dms *DomainMappingStatus) MarkReferenceResolved() { - domainMappingCondSet.Manage(dms).MarkTrue(DomainMappingConditionReferenceResolved) -} - -// MarkReferenceNotResolved sets the DomainMappingConditionReferenceResolved -// condition to false. -func (dms *DomainMappingStatus) MarkReferenceNotResolved(reason string) { - domainMappingCondSet.Manage(dms).MarkFalse(DomainMappingConditionReferenceResolved, "ResolveFailed", reason) -} - -// PropagateIngressStatus updates the DomainMappingConditionIngressReady -// condition according to the underlying Ingress's status. -func (dms *DomainMappingStatus) PropagateIngressStatus(cs netv1alpha1.IngressStatus) { - cc := cs.GetCondition(netv1alpha1.IngressConditionReady) - if cc == nil { - dms.MarkIngressNotConfigured() - return - } - - m := domainMappingCondSet.Manage(dms) - switch cc.Status { - case corev1.ConditionTrue: - m.MarkTrue(DomainMappingConditionIngressReady) - case corev1.ConditionFalse: - m.MarkFalse(DomainMappingConditionIngressReady, cc.Reason, cc.Message) - case corev1.ConditionUnknown: - m.MarkUnknown(DomainMappingConditionIngressReady, cc.Reason, cc.Message) - } -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_lifecycle_test.go b/pkg/apis/serving/v1alpha1/domainmapping_lifecycle_test.go deleted file mode 100644 index 675c448361e7..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_lifecycle_test.go +++ /dev/null @@ -1,337 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "testing" - - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - duckv1 "knative.dev/pkg/apis/duck/v1" - apistest "knative.dev/pkg/apis/testing" -) - -func TestDomainMappingDuckTypes(t *testing.T) { - tests := []struct { - name string - t duck.Implementable - }{{ - name: "conditions", - t: &duckv1.Conditions{}, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - err := duck.VerifyType(&DomainMapping{}, test.t) - if err != nil { - t.Errorf("VerifyType(DomainMapping, %T) = %v", test.t, err) - } - }) - } -} - -func TestDomainMappingGetConditionSet(t *testing.T) { - r := &DomainMapping{} - - if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want { - t.Errorf("GetTopLevelCondition=%v, want=%v", got, want) - } -} - -func TestDomainMappingGetGroupVersionKind(t *testing.T) { - r := &DomainMapping{} - want := schema.GroupVersionKind{ - Group: "serving.knative.dev", - Version: "v1alpha1", - Kind: "DomainMapping", - } - if got := r.GetGroupVersionKind(); got != want { - t.Errorf("got: %v, want: %v", got, want) - } -} - -func TestDomainClaimConditions(t *testing.T) { - dms := &DomainMappingStatus{} - - dms.InitializeConditions() - dms.MarkTLSNotEnabled("AutoTLS not yet available for DomainMapping") - apistest.CheckConditionOngoing(dms, DomainMappingConditionDomainClaimed, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) - - dms.MarkDomainClaimFailed("rejected") - apistest.CheckConditionFailed(dms, DomainMappingConditionDomainClaimed, t) - apistest.CheckConditionFailed(dms, DomainMappingConditionReady, t) - - dms.MarkDomainClaimed() - apistest.CheckConditionSucceeded(dms, DomainMappingConditionDomainClaimed, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) - - dms.MarkReferenceResolved() - dms.PropagateIngressStatus(netv1alpha1.IngressStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: netv1alpha1.IngressConditionReady, - Status: corev1.ConditionTrue, - }}, - }, - }) - apistest.CheckConditionSucceeded(dms, DomainMappingConditionReady, t) - - dms.MarkDomainClaimNotOwned() - apistest.CheckConditionFailed(dms, DomainMappingConditionDomainClaimed, t) - apistest.CheckConditionFailed(dms, DomainMappingConditionReady, t) -} - -func TestReferenceResolvedCondition(t *testing.T) { - dms := &DomainMappingStatus{} - - dms.InitializeConditions() - dms.MarkTLSNotEnabled("AutoTLS not yet available for DomainMapping") - apistest.CheckConditionOngoing(dms, DomainMappingConditionReferenceResolved, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) - - dms.MarkReferenceNotResolved("can't get no resolution") - apistest.CheckConditionFailed(dms, DomainMappingConditionReferenceResolved, t) - apistest.CheckConditionFailed(dms, DomainMappingConditionReady, t) - - dms.MarkReferenceResolved() - apistest.CheckConditionSucceeded(dms, DomainMappingConditionReferenceResolved, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) - - dms.MarkDomainClaimed() - dms.PropagateIngressStatus(netv1alpha1.IngressStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: netv1alpha1.IngressConditionReady, - Status: corev1.ConditionTrue, - }}, - }, - }) - apistest.CheckConditionSucceeded(dms, DomainMappingConditionReady, t) - - dms.MarkReferenceNotResolved("still can't get no resolution") - apistest.CheckConditionFailed(dms, DomainMappingConditionReferenceResolved, t) - apistest.CheckConditionFailed(dms, DomainMappingConditionReady, t) -} - -func TestCertificateNotReady(t *testing.T) { - dms := &DomainMappingStatus{} - - dms.InitializeConditions() - dms.MarkCertificateNotReady("cert pending") - - apistest.CheckConditionOngoing(dms, DomainMappingConditionCertificateProvisioned, t) -} - -func TestCertificateProvisionFailed(t *testing.T) { - dms := &DomainMappingStatus{} - - dms.InitializeConditions() - dms.MarkCertificateProvisionFailed("cert failed") - - apistest.CheckConditionFailed(dms, DomainMappingConditionCertificateProvisioned, t) -} - -func TestDomainMappingNotOwnCertificate(t *testing.T) { - dms := &DomainMappingStatus{} - dms.InitializeConditions() - dms.MarkCertificateNotOwned("cert not owned") - - apistest.CheckConditionFailed(dms, DomainMappingConditionCertificateProvisioned, t) -} - -func TestDomainMappingAutoTLSNotEnabled(t *testing.T) { - dms := &DomainMappingStatus{} - dms.InitializeConditions() - dms.MarkTLSNotEnabled(AutoTLSNotEnabledMessage) - - apistest.CheckConditionSucceeded(dms, DomainMappingConditionCertificateProvisioned, t) -} - -func TestDomainMappingHTTPDowngrade(t *testing.T) { - dms := &DomainMappingStatus{} - dms.InitializeConditions() - dms.MarkHTTPDowngrade("downgraded to HTTP because we can't obtain cert") - - apistest.CheckConditionSucceeded(dms, DomainMappingConditionCertificateProvisioned, t) -} - -func TestPropagateIngressStatus(t *testing.T) { - dms := &DomainMappingStatus{} - - dms.InitializeConditions() - dms.MarkTLSNotEnabled("AutoTLS not yet available for DomainMapping") - apistest.CheckConditionOngoing(dms, DomainMappingConditionIngressReady, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) - - dms.PropagateIngressStatus(netv1alpha1.IngressStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: netv1alpha1.IngressConditionReady, - Status: corev1.ConditionFalse, - }}, - }, - }) - - apistest.CheckConditionFailed(dms, DomainMappingConditionIngressReady, t) - apistest.CheckConditionFailed(dms, DomainMappingConditionReady, t) - - dms.PropagateIngressStatus(netv1alpha1.IngressStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: netv1alpha1.IngressConditionReady, - Status: corev1.ConditionTrue, - }}, - }, - }) - - apistest.CheckConditionSucceeded(dms, DomainMappingConditionIngressReady, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) - - dms.MarkDomainClaimed() - dms.MarkReferenceResolved() - apistest.CheckConditionSucceeded(dms, DomainMappingConditionReady, t) - - dms.PropagateIngressStatus(netv1alpha1.IngressStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: netv1alpha1.IngressConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }) - - apistest.CheckConditionOngoing(dms, DomainMappingConditionIngressReady, t) - apistest.CheckConditionOngoing(dms, DomainMappingConditionReady, t) -} - -func TestDomainMappingIsReady(t *testing.T) { - cases := []struct { - name string - status DomainMappingStatus - isReady bool - }{{ - name: "empty status should not be ready", - status: DomainMappingStatus{}, - isReady: false, - }, { - name: "Different condition type should not be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionIngressReady, - Status: corev1.ConditionTrue, - }}, - }, - }, - isReady: false, - }, { - name: "False condition status should not be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionReady, - Status: corev1.ConditionFalse, - }}, - }, - }, - isReady: false, - }, { - name: "Unknown condition status should not be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionReady, - Status: corev1.ConditionUnknown, - }}, - }, - }, - isReady: false, - }, { - name: "Missing condition status should not be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionReady, - }}, - }, - }, - isReady: false, - }, { - name: "True condition status should be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionReady, - Status: corev1.ConditionTrue, - }}, - }, - }, - isReady: true, - }, { - name: "Multiple conditions with ready status should be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionIngressReady, - Status: corev1.ConditionTrue, - }, { - Type: DomainMappingConditionReady, - Status: corev1.ConditionTrue, - }}, - }, - }, - isReady: true, - }, { - name: "Multiple conditions with ready status false should not be ready", - status: DomainMappingStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{{ - Type: DomainMappingConditionIngressReady, - Status: corev1.ConditionTrue, - }, { - Type: DomainMappingConditionReady, - Status: corev1.ConditionFalse, - }}, - }, - }, - isReady: false, - }} - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - if e, a := tc.isReady, tc.status.IsReady(); e != a { - t.Errorf("%q expected: %v got: %v", tc.name, e, a) - } - - dm := &DomainMapping{} - dm.Status = tc.status - if e, a := tc.isReady, dm.IsReady(); e != a { - t.Errorf("%q expected: %v got: %v", tc.name, e, a) - } - - dm.Generation = 2 - dm.Status.ObservedGeneration = 1 - if dm.IsReady() { - t.Error("Expected DomainMapping not to be Ready when ObservedGeneration != Generation") - } - }) - } -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_types.go b/pkg/apis/serving/v1alpha1/domainmapping_types.go deleted file mode 100644 index 10d30a6b017f..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_types.go +++ /dev/null @@ -1,135 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -// +genclient -// +genreconciler -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// DomainMapping is a mapping from a custom hostname to an Addressable. -type DomainMapping struct { - metav1.TypeMeta `json:",inline"` - // Standard object's metadata. - // More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata - // +optional - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Spec is the desired state of the DomainMapping. - // More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status - // +optional - Spec DomainMappingSpec `json:"spec,omitempty"` - - // Status is the current state of the DomainMapping. - // More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status - // +optional - Status DomainMappingStatus `json:"status,omitempty"` -} - -// Verify that DomainMapping adheres to the appropriate interfaces. -var ( - // Check that DomainMapping may be validated and defaulted. - _ apis.Validatable = (*DomainMapping)(nil) - _ apis.Defaultable = (*DomainMapping)(nil) - - // Check that the type conforms to the duck Knative Resource shape. - _ duckv1.KRShaped = (*DomainMapping)(nil) -) - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// DomainMappingList is a collection of DomainMapping objects. -type DomainMappingList struct { - metav1.TypeMeta `json:",inline"` - // Standard object metadata. - // More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata - // +optional - metav1.ListMeta `json:"metadata,omitempty"` - - // Items is the list of DomainMapping objects. - Items []DomainMapping `json:"items"` -} - -// SecretTLS wrapper for TLS SecretName. -type SecretTLS struct { - // SecretName is the name of the existing secret used to terminate TLS traffic. - SecretName string `json:"secretName"` -} - -// DomainMappingSpec describes the DomainMapping the user wishes to exist. -type DomainMappingSpec struct { - // Ref specifies the target of the Domain Mapping. - // - // The object identified by the Ref must be an Addressable with a URL of the - // form `{name}.{namespace}.{domain}` where `{domain}` is the cluster domain, - // and `{name}` and `{namespace}` are the name and namespace of a Kubernetes - // Service. - // - // This contract is satisfied by Knative types such as Knative Services and - // Knative Routes, and by Kubernetes Services. - Ref duckv1.KReference `json:"ref"` - - // TLS allows the DomainMapping to terminate TLS traffic with an existing secret. - // +optional - TLS *SecretTLS `json:"tls,omitempty"` -} - -// DomainMappingStatus describes the current state of the DomainMapping. -type DomainMappingStatus struct { - duckv1.Status `json:",inline"` - - // URL is the URL of this DomainMapping. - // +optional - URL *apis.URL `json:"url,omitempty"` - - // Address holds the information needed for a DomainMapping to be the target of an event. - // +optional - Address *duckv1.Addressable `json:"address,omitempty"` -} - -const ( - // DomainMappingConditionReady is set when the DomainMapping is configured - // and the Ingress is ready. - DomainMappingConditionReady = apis.ConditionReady - - // DomainMappingConditionReferenceResolved reflects whether the Ref - // has been successfully resolved to an existing object. - DomainMappingConditionReferenceResolved apis.ConditionType = "ReferenceResolved" - - // DomainMappingConditionIngressReady reflects the readiness of the - // underlying Ingress resource. - DomainMappingConditionIngressReady apis.ConditionType = "IngressReady" - - // DomainMappingConditionDomainClaimed reflects that the ClusterDomainClaim - // for this DomainMapping exists, and is owned by this DomainMapping. - DomainMappingConditionDomainClaimed apis.ConditionType = "DomainClaimed" - - // DomainMappingConditionCertificateProvisioned is set to False when the - // Knative Certificates fail to be provisioned for the DomainMapping. - DomainMappingConditionCertificateProvisioned apis.ConditionType = "CertificateProvisioned" -) - -// GetStatus retrieves the status of the DomainMapping. Implements the KRShaped interface. -func (dm *DomainMapping) GetStatus() *duckv1.Status { - return &dm.Status.Status -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_types_test.go b/pkg/apis/serving/v1alpha1/domainmapping_types_test.go deleted file mode 100644 index 8e75105e1c23..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_types_test.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - duckv1 "knative.dev/pkg/apis/duck/v1" -) - -func TestDomainMappingGetStatus(t *testing.T) { - status := &duckv1.Status{} - config := DomainMapping{ - Status: DomainMappingStatus{ - Status: *status, - }, - } - - if !cmp.Equal(config.GetStatus(), status) { - t.Errorf("GetStatus did not retrieve status. Got=%v Want=%v", config.GetStatus(), status) - } -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_validation.go b/pkg/apis/serving/v1alpha1/domainmapping_validation.go deleted file mode 100644 index 3158ef4eccac..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_validation.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "context" - "fmt" - "strings" - - "k8s.io/apimachinery/pkg/util/validation" - "k8s.io/apimachinery/pkg/util/validation/field" - "knative.dev/pkg/apis" - "knative.dev/pkg/network" - "knative.dev/serving/pkg/apis/serving" -) - -// Validate makes sure that DomainMapping is properly configured. -func (dm *DomainMapping) Validate(ctx context.Context) *apis.FieldError { - errs := dm.validateMetadata(ctx).ViaField("metadata") - - ctx = apis.WithinParent(ctx, dm.ObjectMeta) - errs = errs.Also(dm.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec")) - - return errs -} - -// validateMetadata validates the metadata section of a DomainMapping. -func (dm *DomainMapping) validateMetadata(ctx context.Context) (errs *apis.FieldError) { - if dm.GenerateName != "" { - errs = errs.Also(apis.ErrDisallowedFields("generateName")) - } - - err := validation.IsFullyQualifiedDomainName(field.NewPath("name"), dm.Name) - if err != nil { - errs = errs.Also(apis.ErrGeneric(fmt.Sprintf( - "invalid name %q: %s", dm.Name, err.ToAggregate()), "name")) - } - - clusterLocalDomain := network.GetClusterDomainName() - if strings.HasSuffix(dm.Name, "."+clusterLocalDomain) { - errs = errs.Also(apis.ErrGeneric( - fmt.Sprintf("invalid name %q: must not be a subdomain of cluster local domain %q", dm.Name, clusterLocalDomain), "name")) - } - - if apis.IsInUpdate(ctx) { - original := apis.GetBaseline(ctx).(*DomainMapping) - errs = errs.Also( - apis.ValidateCreatorAndModifier(original.Spec, dm.Spec, - original.GetAnnotations(), dm.GetAnnotations(), serving.GroupName).ViaField("annotations"), - ) - } - - return errs -} - -// Validate makes sure the DomainMappingSpec is properly configured. -func (spec *DomainMappingSpec) Validate(ctx context.Context) *apis.FieldError { - return spec.Ref.Validate(ctx).ViaField("ref") -} diff --git a/pkg/apis/serving/v1alpha1/domainmapping_validation_test.go b/pkg/apis/serving/v1alpha1/domainmapping_validation_test.go deleted file mode 100644 index 19497d660711..000000000000 --- a/pkg/apis/serving/v1alpha1/domainmapping_validation_test.go +++ /dev/null @@ -1,287 +0,0 @@ -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/serving/pkg/apis/serving" -) - -func TestDomainMappingValidation(t *testing.T) { - tests := []struct { - name string - dm *DomainMapping - want *apis.FieldError - }{{ - name: "invalid name", - want: apis.ErrGeneric("invalid name \"invalid\": name: Invalid value: \"invalid\": should be a domain with at least two segments separated by dots", "metadata.name"), - dm: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "invalid", - Namespace: "ns", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "some-name.example.com", - APIVersion: "serving.knative.dev/v1", - Kind: "Service", - Namespace: "ns", - }, - }, - }, - }, { - name: "uses GenerateName rather than Name", - want: apis.ErrDisallowedFields("metadata.generateName").Also( - apis.ErrGeneric("invalid name \"\": name: Required value", "metadata.name")), - dm: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - GenerateName: "cant-use-this", - Namespace: "ns", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "some-name.example.com", - APIVersion: "serving.knative.dev/v1", - Kind: "Service", - Namespace: "ns", - }, - }, - }, - }, { - name: "ref in wrong namespace", - want: &apis.FieldError{ - Paths: []string{"spec.ref.namespace"}, - Details: `parent namespace: "good-namespace" does not match ref: "bad-namespace"`, - Message: `mismatched namespaces`, - }, - dm: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "wrong-ref-ns.example.com", - Namespace: "good-namespace", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "some-name", - Namespace: "bad-namespace", - APIVersion: "serving.knative.dev/v1", - Kind: "Service", - }, - }, - }, - }, { - name: "ref missing Kind", - want: apis.ErrMissingField("spec.ref.kind"), - dm: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "wrong-kind.example.com", - Namespace: "ns", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "some-name", - Namespace: "ns", - APIVersion: "serving.knative.dev/v1", - }, - }, - }, - }, { - name: "ref missing ApiVersion", - want: apis.ErrMissingField("spec.ref.apiVersion"), - dm: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "wrong-version.example.com", - Namespace: "ns", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "some-name", - Namespace: "ns", - Kind: "Service", - }, - }, - }, - }, { - name: "cluster local domain name", - want: apis.ErrGeneric("invalid name \"notallowed.svc.cluster.local\": must not be a subdomain of cluster local domain \"cluster.local\"", "metadata.name"), - dm: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "notallowed.svc.cluster.local", - Namespace: "ns", - }, - Spec: DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: "some-name", - Namespace: "ns", - Kind: "Service", - APIVersion: "serving.knative.dev/v1", - }, - }, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - ctx := context.Background() - got := test.dm.Validate(ctx) - - if !cmp.Equal(test.want.Error(), got.Error()) { - t.Errorf("Validate (-want, +got):\n%s", cmp.Diff(test.want.Error(), got.Error())) - } - }) - } -} - -func TestDomainMappingAnnotationUpdate(t *testing.T) { - const ( - u1 = "oveja@knative.dev" - u2 = "cabra@knative.dev" - u3 = "vaca@knative.dev" - ) - spec := func(name string) DomainMappingSpec { - return DomainMappingSpec{ - Ref: duckv1.KReference{ - Name: name, - Namespace: "ns", - Kind: "Service", - APIVersion: "serving.knative.dev/v1", - }, - } - } - tests := []struct { - name string - prev *DomainMapping - this *DomainMapping - want *apis.FieldError - }{{ - name: "update creator annotation", - this: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u2, - serving.UpdaterAnnotation: u1, - }, - }, - Spec: spec("old"), - }, - prev: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u1, - }, - }, - Spec: spec("old"), - }, - want: (&apis.FieldError{Message: "annotation value is immutable", - Paths: []string{serving.CreatorAnnotation}}).ViaField("metadata.annotations"), - }, { - name: "update creator annotation with spec changes", - this: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u2, - serving.UpdaterAnnotation: u1, - }, - }, - Spec: spec("new"), - }, - prev: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u1, - }, - }, - Spec: spec("old"), - }, - want: (&apis.FieldError{Message: "annotation value is immutable", - Paths: []string{serving.CreatorAnnotation}}).ViaField("metadata.annotations"), - }, { - name: "update lastModifier annotation without spec changes", - this: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u2, - }, - }, - Spec: spec("old"), - }, - prev: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u1, - }, - }, - Spec: spec("old"), - }, - want: apis.ErrInvalidValue(u2, serving.UpdaterAnnotation).ViaField("metadata.annotations"), - }, { - name: "update lastModifier annotation with spec changes", - this: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u3, - }, - }, - Spec: spec("new"), - }, - prev: &DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid.example.com", - Namespace: "ns", - Annotations: map[string]string{ - serving.CreatorAnnotation: u1, - serving.UpdaterAnnotation: u1, - }, - }, - Spec: spec("old"), - }, - want: nil, - }} - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - ctx := context.Background() - ctx = apis.WithinUpdate(ctx, test.prev) - if diff := cmp.Diff(test.want.Error(), test.this.Validate(ctx).Error()); diff != "" { - t.Error("Validate (-want, +got) =", diff) - } - }) - } -} diff --git a/pkg/apis/serving/v1alpha1/register.go b/pkg/apis/serving/v1alpha1/register.go index cb2dfa264a54..80d0c7d0a28f 100644 --- a/pkg/apis/serving/v1alpha1/register.go +++ b/pkg/apis/serving/v1alpha1/register.go @@ -1,12 +1,9 @@ /* Copyright 2018 The Knative 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. @@ -46,10 +43,7 @@ var ( // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &DomainMapping{}, - &DomainMappingList{}, - ) + scheme.AddKnownTypes(SchemeGroupVersion) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil } diff --git a/pkg/apis/serving/v1alpha1/register_test.go b/pkg/apis/serving/v1alpha1/register_test.go index 9a432737e239..a47f81726efe 100644 --- a/pkg/apis/serving/v1alpha1/register_test.go +++ b/pkg/apis/serving/v1alpha1/register_test.go @@ -1,12 +1,9 @@ /* Copyright 2018 The Knative 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. diff --git a/pkg/apis/serving/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/serving/v1alpha1/zz_generated.deepcopy.go index f3b515c847c4..ab73107319d1 100644 --- a/pkg/apis/serving/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/serving/v1alpha1/zz_generated.deepcopy.go @@ -21,12 +21,6 @@ limitations under the License. package v1alpha1 -import ( - runtime "k8s.io/apimachinery/pkg/runtime" - apis "knative.dev/pkg/apis" - v1 "knative.dev/pkg/apis/duck/v1" -) - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CannotConvertError) DeepCopyInto(out *CannotConvertError) { *out = *in @@ -42,129 +36,3 @@ func (in *CannotConvertError) DeepCopy() *CannotConvertError { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DomainMapping) DeepCopyInto(out *DomainMapping) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DomainMapping. -func (in *DomainMapping) DeepCopy() *DomainMapping { - if in == nil { - return nil - } - out := new(DomainMapping) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DomainMapping) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DomainMappingList) DeepCopyInto(out *DomainMappingList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]DomainMapping, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DomainMappingList. -func (in *DomainMappingList) DeepCopy() *DomainMappingList { - if in == nil { - return nil - } - out := new(DomainMappingList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DomainMappingList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DomainMappingSpec) DeepCopyInto(out *DomainMappingSpec) { - *out = *in - in.Ref.DeepCopyInto(&out.Ref) - if in.TLS != nil { - in, out := &in.TLS, &out.TLS - *out = new(SecretTLS) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DomainMappingSpec. -func (in *DomainMappingSpec) DeepCopy() *DomainMappingSpec { - if in == nil { - return nil - } - out := new(DomainMappingSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DomainMappingStatus) DeepCopyInto(out *DomainMappingStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - if in.URL != nil { - in, out := &in.URL, &out.URL - *out = new(apis.URL) - (*in).DeepCopyInto(*out) - } - if in.Address != nil { - in, out := &in.Address, &out.Address - *out = new(v1.Addressable) - (*in).DeepCopyInto(*out) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DomainMappingStatus. -func (in *DomainMappingStatus) DeepCopy() *DomainMappingStatus { - if in == nil { - return nil - } - out := new(DomainMappingStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SecretTLS) DeepCopyInto(out *SecretTLS) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretTLS. -func (in *SecretTLS) DeepCopy() *SecretTLS { - if in == nil { - return nil - } - out := new(SecretTLS) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/client/clientset/versioned/typed/serving/v1alpha1/domainmapping.go b/pkg/client/clientset/versioned/typed/serving/v1alpha1/domainmapping.go deleted file mode 100644 index ebf411346772..000000000000 --- a/pkg/client/clientset/versioned/typed/serving/v1alpha1/domainmapping.go +++ /dev/null @@ -1,195 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - scheme "knative.dev/serving/pkg/client/clientset/versioned/scheme" -) - -// DomainMappingsGetter has a method to return a DomainMappingInterface. -// A group's client should implement this interface. -type DomainMappingsGetter interface { - DomainMappings(namespace string) DomainMappingInterface -} - -// DomainMappingInterface has methods to work with DomainMapping resources. -type DomainMappingInterface interface { - Create(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.CreateOptions) (*v1alpha1.DomainMapping, error) - Update(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.UpdateOptions) (*v1alpha1.DomainMapping, error) - UpdateStatus(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.UpdateOptions) (*v1alpha1.DomainMapping, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.DomainMapping, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.DomainMappingList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DomainMapping, err error) - DomainMappingExpansion -} - -// domainMappings implements DomainMappingInterface -type domainMappings struct { - client rest.Interface - ns string -} - -// newDomainMappings returns a DomainMappings -func newDomainMappings(c *ServingV1alpha1Client, namespace string) *domainMappings { - return &domainMappings{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the domainMapping, and returns the corresponding domainMapping object, and an error if there is any. -func (c *domainMappings) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DomainMapping, err error) { - result = &v1alpha1.DomainMapping{} - err = c.client.Get(). - Namespace(c.ns). - Resource("domainmappings"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of DomainMappings that match those selectors. -func (c *domainMappings) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DomainMappingList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.DomainMappingList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("domainmappings"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested domainMappings. -func (c *domainMappings) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("domainmappings"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a domainMapping and creates it. Returns the server's representation of the domainMapping, and an error, if there is any. -func (c *domainMappings) Create(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.CreateOptions) (result *v1alpha1.DomainMapping, err error) { - result = &v1alpha1.DomainMapping{} - err = c.client.Post(). - Namespace(c.ns). - Resource("domainmappings"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(domainMapping). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a domainMapping and updates it. Returns the server's representation of the domainMapping, and an error, if there is any. -func (c *domainMappings) Update(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.UpdateOptions) (result *v1alpha1.DomainMapping, err error) { - result = &v1alpha1.DomainMapping{} - err = c.client.Put(). - Namespace(c.ns). - Resource("domainmappings"). - Name(domainMapping.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(domainMapping). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *domainMappings) UpdateStatus(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.UpdateOptions) (result *v1alpha1.DomainMapping, err error) { - result = &v1alpha1.DomainMapping{} - err = c.client.Put(). - Namespace(c.ns). - Resource("domainmappings"). - Name(domainMapping.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(domainMapping). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the domainMapping and deletes it. Returns an error if one occurs. -func (c *domainMappings) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("domainmappings"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *domainMappings) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("domainmappings"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched domainMapping. -func (c *domainMappings) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DomainMapping, err error) { - result = &v1alpha1.DomainMapping{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("domainmappings"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_domainmapping.go b/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_domainmapping.go deleted file mode 100644 index fd418626b5ad..000000000000 --- a/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_domainmapping.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" -) - -// FakeDomainMappings implements DomainMappingInterface -type FakeDomainMappings struct { - Fake *FakeServingV1alpha1 - ns string -} - -var domainmappingsResource = schema.GroupVersionResource{Group: "serving.knative.dev", Version: "v1alpha1", Resource: "domainmappings"} - -var domainmappingsKind = schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1alpha1", Kind: "DomainMapping"} - -// Get takes name of the domainMapping, and returns the corresponding domainMapping object, and an error if there is any. -func (c *FakeDomainMappings) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DomainMapping, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(domainmappingsResource, c.ns, name), &v1alpha1.DomainMapping{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.DomainMapping), err -} - -// List takes label and field selectors, and returns the list of DomainMappings that match those selectors. -func (c *FakeDomainMappings) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DomainMappingList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(domainmappingsResource, domainmappingsKind, c.ns, opts), &v1alpha1.DomainMappingList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.DomainMappingList{ListMeta: obj.(*v1alpha1.DomainMappingList).ListMeta} - for _, item := range obj.(*v1alpha1.DomainMappingList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested domainMappings. -func (c *FakeDomainMappings) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(domainmappingsResource, c.ns, opts)) - -} - -// Create takes the representation of a domainMapping and creates it. Returns the server's representation of the domainMapping, and an error, if there is any. -func (c *FakeDomainMappings) Create(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.CreateOptions) (result *v1alpha1.DomainMapping, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(domainmappingsResource, c.ns, domainMapping), &v1alpha1.DomainMapping{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.DomainMapping), err -} - -// Update takes the representation of a domainMapping and updates it. Returns the server's representation of the domainMapping, and an error, if there is any. -func (c *FakeDomainMappings) Update(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.UpdateOptions) (result *v1alpha1.DomainMapping, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(domainmappingsResource, c.ns, domainMapping), &v1alpha1.DomainMapping{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.DomainMapping), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeDomainMappings) UpdateStatus(ctx context.Context, domainMapping *v1alpha1.DomainMapping, opts v1.UpdateOptions) (*v1alpha1.DomainMapping, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(domainmappingsResource, "status", c.ns, domainMapping), &v1alpha1.DomainMapping{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.DomainMapping), err -} - -// Delete takes name of the domainMapping and deletes it. Returns an error if one occurs. -func (c *FakeDomainMappings) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(domainmappingsResource, c.ns, name, opts), &v1alpha1.DomainMapping{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeDomainMappings) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(domainmappingsResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.DomainMappingList{}) - return err -} - -// Patch applies the patch and returns the patched domainMapping. -func (c *FakeDomainMappings) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DomainMapping, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(domainmappingsResource, c.ns, name, pt, data, subresources...), &v1alpha1.DomainMapping{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.DomainMapping), err -} diff --git a/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_serving_client.go b/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_serving_client.go index 188ad1bb1eaa..7056875bd736 100644 --- a/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_serving_client.go +++ b/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake/fake_serving_client.go @@ -21,17 +21,12 @@ package fake import ( rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" ) type FakeServingV1alpha1 struct { *testing.Fake } -func (c *FakeServingV1alpha1) DomainMappings(namespace string) v1alpha1.DomainMappingInterface { - return &FakeDomainMappings{c, namespace} -} - // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeServingV1alpha1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/serving/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/serving/v1alpha1/generated_expansion.go index b0fbfa41365a..778e66cf02fb 100644 --- a/pkg/client/clientset/versioned/typed/serving/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/serving/v1alpha1/generated_expansion.go @@ -17,5 +17,3 @@ limitations under the License. // Code generated by client-gen. DO NOT EDIT. package v1alpha1 - -type DomainMappingExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/serving/v1alpha1/serving_client.go b/pkg/client/clientset/versioned/typed/serving/v1alpha1/serving_client.go index 895b90034c9c..acb1e303f70d 100644 --- a/pkg/client/clientset/versioned/typed/serving/v1alpha1/serving_client.go +++ b/pkg/client/clientset/versioned/typed/serving/v1alpha1/serving_client.go @@ -28,7 +28,6 @@ import ( type ServingV1alpha1Interface interface { RESTClient() rest.Interface - DomainMappingsGetter } // ServingV1alpha1Client is used to interact with features provided by the serving.knative.dev group. @@ -36,10 +35,6 @@ type ServingV1alpha1Client struct { restClient rest.Interface } -func (c *ServingV1alpha1Client) DomainMappings(namespace string) DomainMappingInterface { - return newDomainMappings(c, namespace) -} - // NewForConfig creates a new ServingV1alpha1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index cc807feddec3..2ef64b4328e1 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -25,7 +25,6 @@ import ( cache "k8s.io/client-go/tools/cache" v1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" v1 "knative.dev/serving/pkg/apis/serving/v1" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" v1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1" ) @@ -71,10 +70,6 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v1.SchemeGroupVersion.WithResource("services"): return &genericInformer{resource: resource.GroupResource(), informer: f.Serving().V1().Services().Informer()}, nil - // Group=serving.knative.dev, Version=v1alpha1 - case servingv1alpha1.SchemeGroupVersion.WithResource("domainmappings"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Serving().V1alpha1().DomainMappings().Informer()}, nil - // Group=serving.knative.dev, Version=v1beta1 case v1beta1.SchemeGroupVersion.WithResource("domainmappings"): return &genericInformer{resource: resource.GroupResource(), informer: f.Serving().V1beta1().DomainMappings().Informer()}, nil diff --git a/pkg/client/informers/externalversions/serving/interface.go b/pkg/client/informers/externalversions/serving/interface.go index eff5fa4ede1e..5763b5c07dae 100644 --- a/pkg/client/informers/externalversions/serving/interface.go +++ b/pkg/client/informers/externalversions/serving/interface.go @@ -21,7 +21,6 @@ package serving import ( internalinterfaces "knative.dev/serving/pkg/client/informers/externalversions/internalinterfaces" v1 "knative.dev/serving/pkg/client/informers/externalversions/serving/v1" - v1alpha1 "knative.dev/serving/pkg/client/informers/externalversions/serving/v1alpha1" v1beta1 "knative.dev/serving/pkg/client/informers/externalversions/serving/v1beta1" ) @@ -31,8 +30,6 @@ type Interface interface { V1() v1.Interface // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.Interface - // V1alpha1 provides access to shared informers for resources in V1alpha1. - V1alpha1() v1alpha1.Interface } type group struct { @@ -55,8 +52,3 @@ func (g *group) V1() v1.Interface { func (g *group) V1beta1() v1beta1.Interface { return v1beta1.New(g.factory, g.namespace, g.tweakListOptions) } - -// V1alpha1 returns a new v1alpha1.Interface. -func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} diff --git a/pkg/client/informers/externalversions/serving/v1alpha1/domainmapping.go b/pkg/client/informers/externalversions/serving/v1alpha1/domainmapping.go deleted file mode 100644 index eddbfd5dd407..000000000000 --- a/pkg/client/informers/externalversions/serving/v1alpha1/domainmapping.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - versioned "knative.dev/serving/pkg/client/clientset/versioned" - internalinterfaces "knative.dev/serving/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/serving/pkg/client/listers/serving/v1alpha1" -) - -// DomainMappingInformer provides access to a shared informer and lister for -// DomainMappings. -type DomainMappingInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.DomainMappingLister -} - -type domainMappingInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewDomainMappingInformer constructs a new informer for DomainMapping type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewDomainMappingInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredDomainMappingInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredDomainMappingInformer constructs a new informer for DomainMapping type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredDomainMappingInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.ServingV1alpha1().DomainMappings(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.ServingV1alpha1().DomainMappings(namespace).Watch(context.TODO(), options) - }, - }, - &servingv1alpha1.DomainMapping{}, - resyncPeriod, - indexers, - ) -} - -func (f *domainMappingInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredDomainMappingInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *domainMappingInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&servingv1alpha1.DomainMapping{}, f.defaultInformer) -} - -func (f *domainMappingInformer) Lister() v1alpha1.DomainMappingLister { - return v1alpha1.NewDomainMappingLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/informers/externalversions/serving/v1alpha1/interface.go b/pkg/client/informers/externalversions/serving/v1alpha1/interface.go deleted file mode 100644 index b979e49745f8..000000000000 --- a/pkg/client/informers/externalversions/serving/v1alpha1/interface.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - internalinterfaces "knative.dev/serving/pkg/client/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // DomainMappings returns a DomainMappingInformer. - DomainMappings() DomainMappingInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// DomainMappings returns a DomainMappingInformer. -func (v *version) DomainMappings() DomainMappingInformer { - return &domainMappingInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/domainmapping.go b/pkg/client/injection/informers/serving/v1alpha1/domainmapping/domainmapping.go deleted file mode 100644 index f064a30dbec2..000000000000 --- a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/domainmapping.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package domainmapping - -import ( - context "context" - - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" - v1alpha1 "knative.dev/serving/pkg/client/informers/externalversions/serving/v1alpha1" - factory "knative.dev/serving/pkg/client/injection/informers/factory" -) - -func init() { - injection.Default.RegisterInformer(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct{} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := factory.Get(ctx) - inf := f.Serving().V1alpha1().DomainMappings() - return context.WithValue(ctx, Key{}, inf), inf.Informer() -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context) v1alpha1.DomainMappingInformer { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch knative.dev/serving/pkg/client/informers/externalversions/serving/v1alpha1.DomainMappingInformer from context.") - } - return untyped.(v1alpha1.DomainMappingInformer) -} diff --git a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/fake/fake.go b/pkg/client/injection/informers/serving/v1alpha1/domainmapping/fake/fake.go deleted file mode 100644 index daa555b11213..000000000000 --- a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/fake/fake.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - fake "knative.dev/serving/pkg/client/injection/informers/factory/fake" - domainmapping "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/domainmapping" -) - -var Get = domainmapping.Get - -func init() { - injection.Fake.RegisterInformer(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, controller.Informer) { - f := fake.Get(ctx) - inf := f.Serving().V1alpha1().DomainMappings() - return context.WithValue(ctx, domainmapping.Key{}, inf), inf.Informer() -} diff --git a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/domainmapping.go b/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/domainmapping.go deleted file mode 100644 index 2add2f46b289..000000000000 --- a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/domainmapping.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package filtered - -import ( - context "context" - - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" - v1alpha1 "knative.dev/serving/pkg/client/informers/externalversions/serving/v1alpha1" - filtered "knative.dev/serving/pkg/client/injection/informers/factory/filtered" -) - -func init() { - injection.Default.RegisterFilteredInformers(withInformer) -} - -// Key is used for associating the Informer inside the context.Context. -type Key struct { - Selector string -} - -func withInformer(ctx context.Context) (context.Context, []controller.Informer) { - untyped := ctx.Value(filtered.LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - infs := []controller.Informer{} - for _, selector := range labelSelectors { - f := filtered.Get(ctx, selector) - inf := f.Serving().V1alpha1().DomainMappings() - ctx = context.WithValue(ctx, Key{Selector: selector}, inf) - infs = append(infs, inf.Informer()) - } - return ctx, infs -} - -// Get extracts the typed informer from the context. -func Get(ctx context.Context, selector string) v1alpha1.DomainMappingInformer { - untyped := ctx.Value(Key{Selector: selector}) - if untyped == nil { - logging.FromContext(ctx).Panicf( - "Unable to fetch knative.dev/serving/pkg/client/informers/externalversions/serving/v1alpha1.DomainMappingInformer with selector %s from context.", selector) - } - return untyped.(v1alpha1.DomainMappingInformer) -} diff --git a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/fake/fake.go b/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/fake/fake.go deleted file mode 100644 index 4642603d619f..000000000000 --- a/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered/fake/fake.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package fake - -import ( - context "context" - - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" - factoryfiltered "knative.dev/serving/pkg/client/injection/informers/factory/filtered" - filtered "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/domainmapping/filtered" -) - -var Get = filtered.Get - -func init() { - injection.Fake.RegisterFilteredInformers(withInformer) -} - -func withInformer(ctx context.Context) (context.Context, []controller.Informer) { - untyped := ctx.Value(factoryfiltered.LabelKey{}) - if untyped == nil { - logging.FromContext(ctx).Panic( - "Unable to fetch labelkey from context.") - } - labelSelectors := untyped.([]string) - infs := []controller.Informer{} - for _, selector := range labelSelectors { - f := factoryfiltered.Get(ctx, selector) - inf := f.Serving().V1alpha1().DomainMappings() - ctx = context.WithValue(ctx, filtered.Key{Selector: selector}, inf) - infs = append(infs, inf.Informer()) - } - return ctx, infs -} diff --git a/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/controller.go b/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/controller.go deleted file mode 100644 index c9c593a9f481..000000000000 --- a/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/controller.go +++ /dev/null @@ -1,170 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package domainmapping - -import ( - context "context" - fmt "fmt" - reflect "reflect" - strings "strings" - - zap "go.uber.org/zap" - corev1 "k8s.io/api/core/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - scheme "k8s.io/client-go/kubernetes/scheme" - v1 "k8s.io/client-go/kubernetes/typed/core/v1" - record "k8s.io/client-go/tools/record" - kubeclient "knative.dev/pkg/client/injection/kube/client" - controller "knative.dev/pkg/controller" - logging "knative.dev/pkg/logging" - logkey "knative.dev/pkg/logging/logkey" - reconciler "knative.dev/pkg/reconciler" - versionedscheme "knative.dev/serving/pkg/client/clientset/versioned/scheme" - client "knative.dev/serving/pkg/client/injection/client" - domainmapping "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/domainmapping" -) - -const ( - defaultControllerAgentName = "domainmapping-controller" - defaultFinalizerName = "domainmappings.serving.knative.dev" -) - -// NewImpl returns a controller.Impl that handles queuing and feeding work from -// the queue through an implementation of controller.Reconciler, delegating to -// the provided Interface and optional Finalizer methods. OptionsFn is used to return -// controller.ControllerOptions to be used by the internal reconciler. -func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsFn) *controller.Impl { - logger := logging.FromContext(ctx) - - // Check the options function input. It should be 0 or 1. - if len(optionsFns) > 1 { - logger.Fatal("Up to one options function is supported, found: ", len(optionsFns)) - } - - domainmappingInformer := domainmapping.Get(ctx) - - lister := domainmappingInformer.Lister() - - var promoteFilterFunc func(obj interface{}) bool - var promoteFunc = func(bkt reconciler.Bucket) {} - - rec := &reconcilerImpl{ - LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ - PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { - - // Signal promotion event - promoteFunc(bkt) - - all, err := lister.List(labels.Everything()) - if err != nil { - return err - } - for _, elt := range all { - if promoteFilterFunc != nil { - if ok := promoteFilterFunc(elt); !ok { - continue - } - } - enq(bkt, types.NamespacedName{ - Namespace: elt.GetNamespace(), - Name: elt.GetName(), - }) - } - return nil - }, - }, - Client: client.Get(ctx), - Lister: lister, - reconciler: r, - finalizerName: defaultFinalizerName, - } - - ctrType := reflect.TypeOf(r).Elem() - ctrTypeName := fmt.Sprintf("%s.%s", ctrType.PkgPath(), ctrType.Name()) - ctrTypeName = strings.ReplaceAll(ctrTypeName, "/", ".") - - logger = logger.With( - zap.String(logkey.ControllerType, ctrTypeName), - zap.String(logkey.Kind, "serving.knative.dev.DomainMapping"), - ) - - impl := controller.NewContext(ctx, rec, controller.ControllerOptions{WorkQueueName: ctrTypeName, Logger: logger}) - agentName := defaultControllerAgentName - - // Pass impl to the options. Save any optional results. - for _, fn := range optionsFns { - opts := fn(impl) - if opts.ConfigStore != nil { - rec.configStore = opts.ConfigStore - } - if opts.FinalizerName != "" { - rec.finalizerName = opts.FinalizerName - } - if opts.AgentName != "" { - agentName = opts.AgentName - } - if opts.SkipStatusUpdates { - rec.skipStatusUpdates = true - } - if opts.DemoteFunc != nil { - rec.DemoteFunc = opts.DemoteFunc - } - if opts.PromoteFilterFunc != nil { - promoteFilterFunc = opts.PromoteFilterFunc - } - if opts.PromoteFunc != nil { - promoteFunc = opts.PromoteFunc - } - } - - rec.Recorder = createRecorder(ctx, agentName) - - return impl -} - -func createRecorder(ctx context.Context, agentName string) record.EventRecorder { - logger := logging.FromContext(ctx) - - recorder := controller.GetEventRecorder(ctx) - if recorder == nil { - // Create event broadcaster - logger.Debug("Creating event broadcaster") - eventBroadcaster := record.NewBroadcaster() - watches := []watch.Interface{ - eventBroadcaster.StartLogging(logger.Named("event-broadcaster").Infof), - eventBroadcaster.StartRecordingToSink( - &v1.EventSinkImpl{Interface: kubeclient.Get(ctx).CoreV1().Events("")}), - } - recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: agentName}) - go func() { - <-ctx.Done() - for _, w := range watches { - w.Stop() - } - }() - } - - return recorder -} - -func init() { - versionedscheme.AddToScheme(scheme.Scheme) -} diff --git a/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/reconciler.go b/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/reconciler.go deleted file mode 100644 index c73c7ce25542..000000000000 --- a/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/reconciler.go +++ /dev/null @@ -1,440 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package domainmapping - -import ( - context "context" - json "encoding/json" - fmt "fmt" - - zap "go.uber.org/zap" - "go.uber.org/zap/zapcore" - v1 "k8s.io/api/core/v1" - equality "k8s.io/apimachinery/pkg/api/equality" - errors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - sets "k8s.io/apimachinery/pkg/util/sets" - record "k8s.io/client-go/tools/record" - controller "knative.dev/pkg/controller" - kmp "knative.dev/pkg/kmp" - logging "knative.dev/pkg/logging" - reconciler "knative.dev/pkg/reconciler" - v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - versioned "knative.dev/serving/pkg/client/clientset/versioned" - servingv1alpha1 "knative.dev/serving/pkg/client/listers/serving/v1alpha1" -) - -// Interface defines the strongly typed interfaces to be implemented by a -// controller reconciling v1alpha1.DomainMapping. -type Interface interface { - // ReconcileKind implements custom logic to reconcile v1alpha1.DomainMapping. Any changes - // to the objects .Status or .Finalizers will be propagated to the stored - // object. It is recommended that implementors do not call any update calls - // for the Kind inside of ReconcileKind, it is the responsibility of the calling - // controller to propagate those properties. The resource passed to ReconcileKind - // will always have an empty deletion timestamp. - ReconcileKind(ctx context.Context, o *v1alpha1.DomainMapping) reconciler.Event -} - -// Finalizer defines the strongly typed interfaces to be implemented by a -// controller finalizing v1alpha1.DomainMapping. -type Finalizer interface { - // FinalizeKind implements custom logic to finalize v1alpha1.DomainMapping. Any changes - // to the objects .Status or .Finalizers will be ignored. Returning a nil or - // Normal type reconciler.Event will allow the finalizer to be deleted on - // the resource. The resource passed to FinalizeKind will always have a set - // deletion timestamp. - FinalizeKind(ctx context.Context, o *v1alpha1.DomainMapping) reconciler.Event -} - -// ReadOnlyInterface defines the strongly typed interfaces to be implemented by a -// controller reconciling v1alpha1.DomainMapping if they want to process resources for which -// they are not the leader. -type ReadOnlyInterface interface { - // ObserveKind implements logic to observe v1alpha1.DomainMapping. - // This method should not write to the API. - ObserveKind(ctx context.Context, o *v1alpha1.DomainMapping) reconciler.Event -} - -type doReconcile func(ctx context.Context, o *v1alpha1.DomainMapping) reconciler.Event - -// reconcilerImpl implements controller.Reconciler for v1alpha1.DomainMapping resources. -type reconcilerImpl struct { - // LeaderAwareFuncs is inlined to help us implement reconciler.LeaderAware. - reconciler.LeaderAwareFuncs - - // Client is used to write back status updates. - Client versioned.Interface - - // Listers index properties about resources. - Lister servingv1alpha1.DomainMappingLister - - // Recorder is an event recorder for recording Event resources to the - // Kubernetes API. - Recorder record.EventRecorder - - // configStore allows for decorating a context with config maps. - // +optional - configStore reconciler.ConfigStore - - // reconciler is the implementation of the business logic of the resource. - reconciler Interface - - // finalizerName is the name of the finalizer to reconcile. - finalizerName string - - // skipStatusUpdates configures whether or not this reconciler automatically updates - // the status of the reconciled resource. - skipStatusUpdates bool -} - -// Check that our Reconciler implements controller.Reconciler. -var _ controller.Reconciler = (*reconcilerImpl)(nil) - -// Check that our generated Reconciler is always LeaderAware. -var _ reconciler.LeaderAware = (*reconcilerImpl)(nil) - -func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister servingv1alpha1.DomainMappingLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { - // Check the options function input. It should be 0 or 1. - if len(options) > 1 { - logger.Fatal("Up to one options struct is supported, found: ", len(options)) - } - - // Fail fast when users inadvertently implement the other LeaderAware interface. - // For the typed reconcilers, Promote shouldn't take any arguments. - if _, ok := r.(reconciler.LeaderAware); ok { - logger.Fatalf("%T implements the incorrect LeaderAware interface. Promote() should not take an argument as genreconciler handles the enqueuing automatically.", r) - } - - rec := &reconcilerImpl{ - LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ - PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { - all, err := lister.List(labels.Everything()) - if err != nil { - return err - } - for _, elt := range all { - // TODO: Consider letting users specify a filter in options. - enq(bkt, types.NamespacedName{ - Namespace: elt.GetNamespace(), - Name: elt.GetName(), - }) - } - return nil - }, - }, - Client: client, - Lister: lister, - Recorder: recorder, - reconciler: r, - finalizerName: defaultFinalizerName, - } - - for _, opts := range options { - if opts.ConfigStore != nil { - rec.configStore = opts.ConfigStore - } - if opts.FinalizerName != "" { - rec.finalizerName = opts.FinalizerName - } - if opts.SkipStatusUpdates { - rec.skipStatusUpdates = true - } - if opts.DemoteFunc != nil { - rec.DemoteFunc = opts.DemoteFunc - } - } - - return rec -} - -// Reconcile implements controller.Reconciler -func (r *reconcilerImpl) Reconcile(ctx context.Context, key string) error { - logger := logging.FromContext(ctx) - - // Initialize the reconciler state. This will convert the namespace/name - // string into a distinct namespace and name, determine if this instance of - // the reconciler is the leader, and any additional interfaces implemented - // by the reconciler. Returns an error is the resource key is invalid. - s, err := newState(key, r) - if err != nil { - logger.Error("Invalid resource key: ", key) - return nil - } - - // If we are not the leader, and we don't implement either ReadOnly - // observer interfaces, then take a fast-path out. - if s.isNotLeaderNorObserver() { - return controller.NewSkipKey(key) - } - - // If configStore is set, attach the frozen configuration to the context. - if r.configStore != nil { - ctx = r.configStore.ToContext(ctx) - } - - // Add the recorder to context. - ctx = controller.WithEventRecorder(ctx, r.Recorder) - - // Get the resource with this namespace/name. - - getter := r.Lister.DomainMappings(s.namespace) - - original, err := getter.Get(s.name) - - if errors.IsNotFound(err) { - // The resource may no longer exist, in which case we stop processing and call - // the ObserveDeletion handler if appropriate. - logger.Debugf("Resource %q no longer exists", key) - if del, ok := r.reconciler.(reconciler.OnDeletionInterface); ok { - return del.ObserveDeletion(ctx, types.NamespacedName{ - Namespace: s.namespace, - Name: s.name, - }) - } - return nil - } else if err != nil { - return err - } - - // Don't modify the informers copy. - resource := original.DeepCopy() - - var reconcileEvent reconciler.Event - - name, do := s.reconcileMethodFor(resource) - // Append the target method to the logger. - logger = logger.With(zap.String("targetMethod", name)) - switch name { - case reconciler.DoReconcileKind: - // Set and update the finalizer on resource if r.reconciler - // implements Finalizer. - if resource, err = r.setFinalizerIfFinalizer(ctx, resource); err != nil { - return fmt.Errorf("failed to set finalizers: %w", err) - } - - if !r.skipStatusUpdates { - reconciler.PreProcessReconcile(ctx, resource) - } - - // Reconcile this copy of the resource and then write back any status - // updates regardless of whether the reconciliation errored out. - reconcileEvent = do(ctx, resource) - - if !r.skipStatusUpdates { - reconciler.PostProcessReconcile(ctx, resource, original) - } - - case reconciler.DoFinalizeKind: - // For finalizing reconcilers, if this resource being marked for deletion - // and reconciled cleanly (nil or normal event), remove the finalizer. - reconcileEvent = do(ctx, resource) - - if resource, err = r.clearFinalizer(ctx, resource, reconcileEvent); err != nil { - return fmt.Errorf("failed to clear finalizers: %w", err) - } - - case reconciler.DoObserveKind: - // Observe any changes to this resource, since we are not the leader. - reconcileEvent = do(ctx, resource) - - } - - // Synchronize the status. - switch { - case r.skipStatusUpdates: - // This reconciler implementation is configured to skip resource updates. - // This may mean this reconciler does not observe spec, but reconciles external changes. - case equality.Semantic.DeepEqual(original.Status, resource.Status): - // If we didn't change anything then don't call updateStatus. - // This is important because the copy we loaded from the injectionInformer's - // cache may be stale and we don't want to overwrite a prior update - // to status with this stale state. - case !s.isLeader: - // High-availability reconcilers may have many replicas watching the resource, but only - // the elected leader is expected to write modifications. - logger.Warn("Saw status changes when we aren't the leader!") - default: - if err = r.updateStatus(ctx, logger, original, resource); err != nil { - logger.Warnw("Failed to update resource status", zap.Error(err)) - r.Recorder.Eventf(resource, v1.EventTypeWarning, "UpdateFailed", - "Failed to update status for %q: %v", resource.Name, err) - return err - } - } - - // Report the reconciler event, if any. - if reconcileEvent != nil { - var event *reconciler.ReconcilerEvent - if reconciler.EventAs(reconcileEvent, &event) { - logger.Infow("Returned an event", zap.Any("event", reconcileEvent)) - r.Recorder.Event(resource, event.EventType, event.Reason, event.Error()) - - // the event was wrapped inside an error, consider the reconciliation as failed - if _, isEvent := reconcileEvent.(*reconciler.ReconcilerEvent); !isEvent { - return reconcileEvent - } - return nil - } - - if controller.IsSkipKey(reconcileEvent) { - // This is a wrapped error, don't emit an event. - } else if ok, _ := controller.IsRequeueKey(reconcileEvent); ok { - // This is a wrapped error, don't emit an event. - } else { - logger.Errorw("Returned an error", zap.Error(reconcileEvent)) - r.Recorder.Event(resource, v1.EventTypeWarning, "InternalError", reconcileEvent.Error()) - } - return reconcileEvent - } - - return nil -} - -func (r *reconcilerImpl) updateStatus(ctx context.Context, logger *zap.SugaredLogger, existing *v1alpha1.DomainMapping, desired *v1alpha1.DomainMapping) error { - existing = existing.DeepCopy() - return reconciler.RetryUpdateConflicts(func(attempts int) (err error) { - // The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API. - if attempts > 0 { - - getter := r.Client.ServingV1alpha1().DomainMappings(desired.Namespace) - - existing, err = getter.Get(ctx, desired.Name, metav1.GetOptions{}) - if err != nil { - return err - } - } - - // If there's nothing to update, just return. - if equality.Semantic.DeepEqual(existing.Status, desired.Status) { - return nil - } - - if logger.Desugar().Core().Enabled(zapcore.DebugLevel) { - if diff, err := kmp.SafeDiff(existing.Status, desired.Status); err == nil && diff != "" { - logger.Debug("Updating status with: ", diff) - } - } - - existing.Status = desired.Status - - updater := r.Client.ServingV1alpha1().DomainMappings(existing.Namespace) - - _, err = updater.UpdateStatus(ctx, existing, metav1.UpdateOptions{}) - return err - }) -} - -// updateFinalizersFiltered will update the Finalizers of the resource. -// TODO: this method could be generic and sync all finalizers. For now it only -// updates defaultFinalizerName or its override. -func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1alpha1.DomainMapping, desiredFinalizers sets.String) (*v1alpha1.DomainMapping, error) { - // Don't modify the informers copy. - existing := resource.DeepCopy() - - var finalizers []string - - // If there's nothing to update, just return. - existingFinalizers := sets.NewString(existing.Finalizers...) - - if desiredFinalizers.Has(r.finalizerName) { - if existingFinalizers.Has(r.finalizerName) { - // Nothing to do. - return resource, nil - } - // Add the finalizer. - finalizers = append(existing.Finalizers, r.finalizerName) - } else { - if !existingFinalizers.Has(r.finalizerName) { - // Nothing to do. - return resource, nil - } - // Remove the finalizer. - existingFinalizers.Delete(r.finalizerName) - finalizers = existingFinalizers.List() - } - - mergePatch := map[string]interface{}{ - "metadata": map[string]interface{}{ - "finalizers": finalizers, - "resourceVersion": existing.ResourceVersion, - }, - } - - patch, err := json.Marshal(mergePatch) - if err != nil { - return resource, err - } - - patcher := r.Client.ServingV1alpha1().DomainMappings(resource.Namespace) - - resourceName := resource.Name - updated, err := patcher.Patch(ctx, resourceName, types.MergePatchType, patch, metav1.PatchOptions{}) - if err != nil { - r.Recorder.Eventf(existing, v1.EventTypeWarning, "FinalizerUpdateFailed", - "Failed to update finalizers for %q: %v", resourceName, err) - } else { - r.Recorder.Eventf(updated, v1.EventTypeNormal, "FinalizerUpdate", - "Updated %q finalizers", resource.GetName()) - } - return updated, err -} - -func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1alpha1.DomainMapping) (*v1alpha1.DomainMapping, error) { - if _, ok := r.reconciler.(Finalizer); !ok { - return resource, nil - } - - finalizers := sets.NewString(resource.Finalizers...) - - // If this resource is not being deleted, mark the finalizer. - if resource.GetDeletionTimestamp().IsZero() { - finalizers.Insert(r.finalizerName) - } - - // Synchronize the finalizers filtered by r.finalizerName. - return r.updateFinalizersFiltered(ctx, resource, finalizers) -} - -func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1alpha1.DomainMapping, reconcileEvent reconciler.Event) (*v1alpha1.DomainMapping, error) { - if _, ok := r.reconciler.(Finalizer); !ok { - return resource, nil - } - if resource.GetDeletionTimestamp().IsZero() { - return resource, nil - } - - finalizers := sets.NewString(resource.Finalizers...) - - if reconcileEvent != nil { - var event *reconciler.ReconcilerEvent - if reconciler.EventAs(reconcileEvent, &event) { - if event.EventType == v1.EventTypeNormal { - finalizers.Delete(r.finalizerName) - } - } - } else { - finalizers.Delete(r.finalizerName) - } - - // Synchronize the finalizers filtered by r.finalizerName. - return r.updateFinalizersFiltered(ctx, resource, finalizers) -} diff --git a/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/state.go b/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/state.go deleted file mode 100644 index ed2e2fb61c3d..000000000000 --- a/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping/state.go +++ /dev/null @@ -1,97 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package domainmapping - -import ( - fmt "fmt" - - types "k8s.io/apimachinery/pkg/types" - cache "k8s.io/client-go/tools/cache" - reconciler "knative.dev/pkg/reconciler" - v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" -) - -// state is used to track the state of a reconciler in a single run. -type state struct { - // key is the original reconciliation key from the queue. - key string - // namespace is the namespace split from the reconciliation key. - namespace string - // name is the name split from the reconciliation key. - name string - // reconciler is the reconciler. - reconciler Interface - // roi is the read only interface cast of the reconciler. - roi ReadOnlyInterface - // isROI (Read Only Interface) the reconciler only observes reconciliation. - isROI bool - // isLeader the instance of the reconciler is the elected leader. - isLeader bool -} - -func newState(key string, r *reconcilerImpl) (*state, error) { - // Convert the namespace/name string into a distinct namespace and name. - namespace, name, err := cache.SplitMetaNamespaceKey(key) - if err != nil { - return nil, fmt.Errorf("invalid resource key: %s", key) - } - - roi, isROI := r.reconciler.(ReadOnlyInterface) - - isLeader := r.IsLeaderFor(types.NamespacedName{ - Namespace: namespace, - Name: name, - }) - - return &state{ - key: key, - namespace: namespace, - name: name, - reconciler: r.reconciler, - roi: roi, - isROI: isROI, - isLeader: isLeader, - }, nil -} - -// isNotLeaderNorObserver checks to see if this reconciler with the current -// state is enabled to do any work or not. -// isNotLeaderNorObserver returns true when there is no work possible for the -// reconciler. -func (s *state) isNotLeaderNorObserver() bool { - if !s.isLeader && !s.isROI { - // If we are not the leader, and we don't implement the ReadOnly - // interface, then take a fast-path out. - return true - } - return false -} - -func (s *state) reconcileMethodFor(o *v1alpha1.DomainMapping) (string, doReconcile) { - if o.GetDeletionTimestamp().IsZero() { - if s.isLeader { - return reconciler.DoReconcileKind, s.reconciler.ReconcileKind - } else if s.isROI { - return reconciler.DoObserveKind, s.roi.ObserveKind - } - } else if fin, ok := s.reconciler.(Finalizer); s.isLeader && ok { - return reconciler.DoFinalizeKind, fin.FinalizeKind - } - return "unknown", nil -} diff --git a/pkg/client/listers/serving/v1alpha1/domainmapping.go b/pkg/client/listers/serving/v1alpha1/domainmapping.go deleted file mode 100644 index 6140e516bcb3..000000000000 --- a/pkg/client/listers/serving/v1alpha1/domainmapping.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" -) - -// DomainMappingLister helps list DomainMappings. -// All objects returned here must be treated as read-only. -type DomainMappingLister interface { - // List lists all DomainMappings in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.DomainMapping, err error) - // DomainMappings returns an object that can list and get DomainMappings. - DomainMappings(namespace string) DomainMappingNamespaceLister - DomainMappingListerExpansion -} - -// domainMappingLister implements the DomainMappingLister interface. -type domainMappingLister struct { - indexer cache.Indexer -} - -// NewDomainMappingLister returns a new DomainMappingLister. -func NewDomainMappingLister(indexer cache.Indexer) DomainMappingLister { - return &domainMappingLister{indexer: indexer} -} - -// List lists all DomainMappings in the indexer. -func (s *domainMappingLister) List(selector labels.Selector) (ret []*v1alpha1.DomainMapping, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.DomainMapping)) - }) - return ret, err -} - -// DomainMappings returns an object that can list and get DomainMappings. -func (s *domainMappingLister) DomainMappings(namespace string) DomainMappingNamespaceLister { - return domainMappingNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// DomainMappingNamespaceLister helps list and get DomainMappings. -// All objects returned here must be treated as read-only. -type DomainMappingNamespaceLister interface { - // List lists all DomainMappings in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.DomainMapping, err error) - // Get retrieves the DomainMapping from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha1.DomainMapping, error) - DomainMappingNamespaceListerExpansion -} - -// domainMappingNamespaceLister implements the DomainMappingNamespaceLister -// interface. -type domainMappingNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all DomainMappings in the indexer for a given namespace. -func (s domainMappingNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.DomainMapping, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.DomainMapping)) - }) - return ret, err -} - -// Get retrieves the DomainMapping from the indexer for a given namespace and name. -func (s domainMappingNamespaceLister) Get(name string) (*v1alpha1.DomainMapping, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("domainmapping"), name) - } - return obj.(*v1alpha1.DomainMapping), nil -} diff --git a/pkg/client/listers/serving/v1alpha1/expansion_generated.go b/pkg/client/listers/serving/v1alpha1/expansion_generated.go deleted file mode 100644 index b87cc19191cb..000000000000 --- a/pkg/client/listers/serving/v1alpha1/expansion_generated.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2022 The Knative 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -// DomainMappingListerExpansion allows custom methods to be added to -// DomainMappingLister. -type DomainMappingListerExpansion interface{} - -// DomainMappingNamespaceListerExpansion allows custom methods to be added to -// DomainMappingNamespaceLister. -type DomainMappingNamespaceListerExpansion interface{} diff --git a/pkg/reconciler/domainmapping/controller.go b/pkg/reconciler/domainmapping/controller.go index 611ccaef0033..e22eb3e99021 100644 --- a/pkg/reconciler/domainmapping/controller.go +++ b/pkg/reconciler/domainmapping/controller.go @@ -29,9 +29,9 @@ import ( "knative.dev/pkg/controller" "knative.dev/pkg/logging" "knative.dev/pkg/resolver" - "knative.dev/serving/pkg/apis/serving/v1alpha1" - "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/domainmapping" - kindreconciler "knative.dev/serving/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping" + "knative.dev/serving/pkg/apis/serving/v1beta1" + "knative.dev/serving/pkg/client/injection/informers/serving/v1beta1/domainmapping" + kindreconciler "knative.dev/serving/pkg/client/injection/reconciler/serving/v1beta1/domainmapping" "knative.dev/serving/pkg/reconciler/domainmapping/config" ) @@ -65,7 +65,7 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl domainmappingInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) handleControllerOf := cache.FilteringResourceEventHandler{ - FilterFunc: controller.FilterController(&v1alpha1.DomainMapping{}), + FilterFunc: controller.FilterController(&v1beta1.DomainMapping{}), Handler: controller.HandleAll(impl.EnqueueControllerOf), } certificateInformer.Informer().AddEventHandler(handleControllerOf) diff --git a/pkg/reconciler/domainmapping/reconciler.go b/pkg/reconciler/domainmapping/reconciler.go index f849bee83b29..1b50168375cd 100644 --- a/pkg/reconciler/domainmapping/reconciler.go +++ b/pkg/reconciler/domainmapping/reconciler.go @@ -44,8 +44,8 @@ import ( "knative.dev/pkg/reconciler" "knative.dev/pkg/resolver" v1 "knative.dev/serving/pkg/apis/serving/v1" - "knative.dev/serving/pkg/apis/serving/v1alpha1" - domainmappingreconciler "knative.dev/serving/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping" + "knative.dev/serving/pkg/apis/serving/v1beta1" + domainmappingreconciler "knative.dev/serving/pkg/client/injection/reconciler/serving/v1beta1/domainmapping" servingnetworking "knative.dev/serving/pkg/networking" "knative.dev/serving/pkg/reconciler/domainmapping/config" "knative.dev/serving/pkg/reconciler/domainmapping/resources" @@ -78,7 +78,7 @@ func (r *Reconciler) GetCertificateLister() networkinglisters.CertificateLister } // ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, dm *v1alpha1.DomainMapping) reconciler.Event { +func (r *Reconciler) ReconcileKind(ctx context.Context, dm *v1beta1.DomainMapping) reconciler.Event { ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultTimeout) defer cancel() @@ -146,7 +146,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, dm *v1alpha1.DomainMappi } // FinalizeKind cleans up the ClusterDomainClaim created by the DomainMapping. -func (r *Reconciler) FinalizeKind(ctx context.Context, dm *v1alpha1.DomainMapping) reconciler.Event { +func (r *Reconciler) FinalizeKind(ctx context.Context, dm *v1beta1.DomainMapping) reconciler.Event { if !config.FromContext(ctx).Network.AutocreateClusterDomainClaims { // If we're not responsible for creating domain claims, we're not responsible for cleaning them up. return nil @@ -171,7 +171,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, dm *v1alpha1.DomainMappin return r.netclient.NetworkingV1alpha1().ClusterDomainClaims().Delete(ctx, dm.Name, metav1.DeleteOptions{}) } -func autoTLSEnabled(ctx context.Context, dm *v1alpha1.DomainMapping) bool { +func autoTLSEnabled(ctx context.Context, dm *v1beta1.DomainMapping) bool { if !config.FromContext(ctx).Network.AutoTLS { return false } @@ -192,9 +192,9 @@ func certClass(ctx context.Context) string { return config.FromContext(ctx).Network.DefaultCertificateClass } -func (r *Reconciler) tls(ctx context.Context, dm *v1alpha1.DomainMapping) ([]netv1alpha1.IngressTLS, []netv1alpha1.HTTP01Challenge, error) { +func (r *Reconciler) tls(ctx context.Context, dm *v1beta1.DomainMapping) ([]netv1alpha1.IngressTLS, []netv1alpha1.HTTP01Challenge, error) { if dm.Spec.TLS != nil { - dm.Status.MarkCertificateNotRequired(v1alpha1.TLSCertificateProvidedExternally) + dm.Status.MarkCertificateNotRequired(v1beta1.TLSCertificateProvidedExternally) dm.Status.URL.Scheme = "https" return []netv1alpha1.IngressTLS{{ Hosts: []string{dm.Name}, @@ -246,7 +246,7 @@ func (r *Reconciler) tls(ctx context.Context, dm *v1alpha1.DomainMapping) ([]net return nil, acmeChallenges, nil } -func (r *Reconciler) reconcileIngress(ctx context.Context, dm *v1alpha1.DomainMapping, desired *netv1alpha1.Ingress) (*netv1alpha1.Ingress, error) { +func (r *Reconciler) reconcileIngress(ctx context.Context, dm *v1beta1.DomainMapping, desired *netv1alpha1.Ingress) (*netv1alpha1.Ingress, error) { recorder := controller.GetEventRecorder(ctx) ingress, err := r.ingressLister.Ingresses(desired.Namespace).Get(desired.Name) if apierrs.IsNotFound(err) { @@ -279,7 +279,7 @@ func (r *Reconciler) reconcileIngress(ctx context.Context, dm *v1alpha1.DomainMa return ingress, err } -func (r *Reconciler) resolveRef(ctx context.Context, dm *v1alpha1.DomainMapping) (host, backendSvc string, err error) { +func (r *Reconciler) resolveRef(ctx context.Context, dm *v1beta1.DomainMapping) (host, backendSvc string, err error) { resolved, err := r.resolver.URIFromKReference(ctx, &dm.Spec.Ref, dm) if err != nil { dm.Status.MarkReferenceNotResolved(err.Error()) @@ -318,7 +318,7 @@ func (r *Reconciler) resolveRef(ctx context.Context, dm *v1alpha1.DomainMapping) return resolved.Host, parts[0], nil } -func (r *Reconciler) reconcileDomainClaim(ctx context.Context, dm *v1alpha1.DomainMapping) error { +func (r *Reconciler) reconcileDomainClaim(ctx context.Context, dm *v1beta1.DomainMapping) error { dc, err := r.domainClaimLister.Get(dm.Name) if err != nil && !apierrs.IsNotFound(err) { return fmt.Errorf("failed to get ClusterDomainClaim: %w", err) @@ -335,7 +335,7 @@ func (r *Reconciler) reconcileDomainClaim(ctx context.Context, dm *v1alpha1.Doma return nil } -func (r *Reconciler) createDomainClaim(ctx context.Context, dm *v1alpha1.DomainMapping) error { +func (r *Reconciler) createDomainClaim(ctx context.Context, dm *v1beta1.DomainMapping) error { if !config.FromContext(ctx).Network.AutocreateClusterDomainClaims { dm.Status.MarkDomainClaimNotOwned() return fmt.Errorf("no ClusterDomainClaim found for domain %q (and autocreate-cluster-domain-claims property is not true)", dm.Name) diff --git a/pkg/reconciler/domainmapping/resources/certificate.go b/pkg/reconciler/domainmapping/resources/certificate.go index 777ccbeb1660..47b795ce4bbd 100644 --- a/pkg/reconciler/domainmapping/resources/certificate.go +++ b/pkg/reconciler/domainmapping/resources/certificate.go @@ -20,7 +20,7 @@ import ( networkingv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1" "knative.dev/pkg/kmeta" "knative.dev/serving/pkg/apis/serving" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" routeresources "knative.dev/serving/pkg/reconciler/route/resources" ) @@ -29,7 +29,7 @@ import ( // This function delegates entirely to routeresources.MakeCertificate, // but we keep it here to hide the `certName`, and `dnsName` logic // from the caller. -func MakeCertificate(dm *v1alpha1.DomainMapping, certClass string) *networkingv1alpha1.Certificate { +func MakeCertificate(dm *v1beta1.DomainMapping, certClass string) *networkingv1alpha1.Certificate { certName := kmeta.ChildName(dm.GetName(), "") return routeresources.MakeCertificate( dm, serving.DomainMappingUIDLabelKey, dm.Name, certName, certClass, dm.Name) diff --git a/pkg/reconciler/domainmapping/resources/certificate_test.go b/pkg/reconciler/domainmapping/resources/certificate_test.go index 820c56e206cf..7145bc0ca061 100644 --- a/pkg/reconciler/domainmapping/resources/certificate_test.go +++ b/pkg/reconciler/domainmapping/resources/certificate_test.go @@ -28,7 +28,7 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/kmeta" "knative.dev/serving/pkg/apis/serving" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" // . "knative.dev/serving/pkg/testing/v1" ) @@ -36,16 +36,16 @@ func TestMakeCertificate(t *testing.T) { certClass := "cert-class" for _, tc := range []struct { name string - dm v1alpha1.DomainMapping + dm v1beta1.DomainMapping want networkingv1alpha1.Certificate }{{ name: "basic", - dm: v1alpha1.DomainMapping{ + dm: v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: "mapping.com", Namespace: "the-namespace", }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ Namespace: "the-namespace", Name: "the-name", @@ -71,7 +71,7 @@ func TestMakeCertificate(t *testing.T) { }, }, { name: "filter last-applied", - dm: v1alpha1.DomainMapping{ + dm: v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: "mapping.com", Namespace: "the-namespace", @@ -80,7 +80,7 @@ func TestMakeCertificate(t *testing.T) { "others": "kept", }, }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ Namespace: "the-namespace", Name: "the-name", diff --git a/pkg/reconciler/domainmapping/resources/domainclaim.go b/pkg/reconciler/domainmapping/resources/domainclaim.go index 4b7cdb74a404..8ff5b58a8d85 100644 --- a/pkg/reconciler/domainmapping/resources/domainclaim.go +++ b/pkg/reconciler/domainmapping/resources/domainclaim.go @@ -19,12 +19,12 @@ package resources import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" ) // MakeDomainClaim creates a ClusterDomainClaim named after the given DomainMapping // and giving ownership of the domain name to the DomainMapping's namespace. -func MakeDomainClaim(dm *v1alpha1.DomainMapping) *netv1alpha1.ClusterDomainClaim { +func MakeDomainClaim(dm *v1beta1.DomainMapping) *netv1alpha1.ClusterDomainClaim { return &netv1alpha1.ClusterDomainClaim{ ObjectMeta: metav1.ObjectMeta{ Name: dm.Name, diff --git a/pkg/reconciler/domainmapping/resources/domainclaim_test.go b/pkg/reconciler/domainmapping/resources/domainclaim_test.go index f3190ff8fcdf..3c54f5bfff45 100644 --- a/pkg/reconciler/domainmapping/resources/domainclaim_test.go +++ b/pkg/reconciler/domainmapping/resources/domainclaim_test.go @@ -22,11 +22,11 @@ import ( "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" ) func TestMakeDomainClaim(t *testing.T) { - got := MakeDomainClaim(&v1alpha1.DomainMapping{ + got := MakeDomainClaim(&v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: "mapping.com", Namespace: "the-namespace", diff --git a/pkg/reconciler/domainmapping/resources/ingress.go b/pkg/reconciler/domainmapping/resources/ingress.go index f9f3b287426b..4d0bc75787c6 100644 --- a/pkg/reconciler/domainmapping/resources/ingress.go +++ b/pkg/reconciler/domainmapping/resources/ingress.go @@ -26,7 +26,7 @@ import ( netheader "knative.dev/networking/pkg/http/header" "knative.dev/pkg/kmeta" "knative.dev/serving/pkg/apis/serving" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" + servingv1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1" routeresources "knative.dev/serving/pkg/reconciler/route/resources" ) @@ -35,7 +35,7 @@ import ( // backend is always in the same namespace also (as this is required by // KIngress). The created ingress will contain a RewriteHost rule to cause the // given hostName to be used as the host. -func MakeIngress(dm *servingv1alpha1.DomainMapping, backendServiceName, hostName, ingressClass string, httpOption netv1alpha1.HTTPOption, tls []netv1alpha1.IngressTLS, acmeChallenges ...netv1alpha1.HTTP01Challenge) *netv1alpha1.Ingress { +func MakeIngress(dm *servingv1beta1.DomainMapping, backendServiceName, hostName, ingressClass string, httpOption netv1alpha1.HTTPOption, tls []netv1alpha1.IngressTLS, acmeChallenges ...netv1alpha1.HTTP01Challenge) *netv1alpha1.Ingress { paths, hosts := routeresources.MakeACMEIngressPaths(acmeChallenges, sets.NewString(dm.GetName())) return &netv1alpha1.Ingress{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/reconciler/domainmapping/resources/ingress_test.go b/pkg/reconciler/domainmapping/resources/ingress_test.go index 781e7e0107c5..759e090ba94e 100644 --- a/pkg/reconciler/domainmapping/resources/ingress_test.go +++ b/pkg/reconciler/domainmapping/resources/ingress_test.go @@ -31,19 +31,19 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/kmeta" "knative.dev/serving/pkg/apis/serving" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" ) func TestMakeIngress(t *testing.T) { for _, tc := range []struct { name string - dm v1alpha1.DomainMapping + dm v1beta1.DomainMapping want netv1alpha1.Ingress tls []netv1alpha1.IngressTLS acmeChallenges []netv1alpha1.HTTP01Challenge }{{ name: "basic", - dm: v1alpha1.DomainMapping{ + dm: v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: "mapping.com", Namespace: "the-namespace", @@ -53,7 +53,7 @@ func TestMakeIngress(t *testing.T) { corev1.LastAppliedConfigAnnotation: "blah", }, }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ Namespace: "the-namespace", Name: "the-name", @@ -95,7 +95,7 @@ func TestMakeIngress(t *testing.T) { }, }, { name: "tls", - dm: v1alpha1.DomainMapping{ + dm: v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: "mapping.com", Namespace: "the-namespace", @@ -105,7 +105,7 @@ func TestMakeIngress(t *testing.T) { corev1.LastAppliedConfigAnnotation: "blah", }, }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ Namespace: "the-namespace", Name: "the-name", @@ -155,7 +155,7 @@ func TestMakeIngress(t *testing.T) { }, }, { name: "challenges", - dm: v1alpha1.DomainMapping{ + dm: v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: "mapping.com", Namespace: "the-namespace", @@ -165,7 +165,7 @@ func TestMakeIngress(t *testing.T) { corev1.LastAppliedConfigAnnotation: "blah", }, }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ Namespace: "the-namespace", Name: "the-name", diff --git a/pkg/reconciler/domainmapping/table_test.go b/pkg/reconciler/domainmapping/table_test.go index c5e3911d1cab..4df125db1e28 100644 --- a/pkg/reconciler/domainmapping/table_test.go +++ b/pkg/reconciler/domainmapping/table_test.go @@ -46,8 +46,9 @@ import ( "knative.dev/serving/pkg/apis/serving" servingv1 "knative.dev/serving/pkg/apis/serving/v1" "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" servingclient "knative.dev/serving/pkg/client/injection/client/fake" - domainmappingreconciler "knative.dev/serving/pkg/client/injection/reconciler/serving/v1alpha1/domainmapping" + domainmappingreconciler "knative.dev/serving/pkg/client/injection/reconciler/serving/v1beta1/domainmapping" "knative.dev/serving/pkg/reconciler/domainmapping/config" "knative.dev/serving/pkg/reconciler/domainmapping/resources" @@ -114,7 +115,7 @@ func TestReconcile(t *testing.T) { WantDeletes: []clientgotesting.DeleteActionImpl{{ ActionImpl: clientgotesting.ActionImpl{ Verb: "delete", - Resource: v1alpha1.SchemeGroupVersion.WithResource("clusterdomainclaims"), + Resource: v1beta1.SchemeGroupVersion.WithResource("clusterdomainclaims"), }, Name: "cleanup.on.aisle-three", }}, @@ -1042,7 +1043,7 @@ func TestReconcileTLSEnabled(t *testing.T) { }, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "FinalizerUpdate", "Updated %q finalizers", "cert.not.owned.ru"), - Eventf(corev1.EventTypeWarning, "InternalError", `notowned: owner: cert.not.owned.ru with Type *v1alpha1.DomainMapping does not own Certificate: "cert.not.owned.ru"`), + Eventf(corev1.EventTypeWarning, "InternalError", `notowned: owner: cert.not.owned.ru with Type *v1beta1.DomainMapping does not own Certificate: "cert.not.owned.ru"`), }, }, { Name: "cert creation failed", @@ -1327,10 +1328,10 @@ func TestReconcileTLSEnabledButDowngraded(t *testing.T) { })) } -type domainMappingOption func(dm *v1alpha1.DomainMapping) +type domainMappingOption func(dm *v1beta1.DomainMapping) -func domainMapping(namespace, name string, opt ...domainMappingOption) *v1alpha1.DomainMapping { - dm := &v1alpha1.DomainMapping{ +func domainMapping(namespace, name string, opt ...domainMappingOption) *v1beta1.DomainMapping { + dm := &v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespace, Name: name, @@ -1343,19 +1344,19 @@ func domainMapping(namespace, name string, opt ...domainMappingOption) *v1alpha1 } func withAnnotations(ans map[string]string) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Annotations = ans } } func withLabels(label map[string]string) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Labels = label } } func withUID(uid types.UID) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.UID = uid } } @@ -1363,7 +1364,7 @@ func withUID(uid types.UID) domainMappingOption { type refOption func(*duckv1.KReference) func withRef(namespace, name string, opt ...refOption) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Spec.Ref.Namespace = namespace dm.Spec.Ref.Name = name dm.Spec.Ref.APIVersion = "serving.knative.dev/v1" @@ -1383,13 +1384,13 @@ func withAPIVersionKind(apiVersion, kind string) refOption { } func withURL(scheme, host string) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Status.URL = &apis.URL{Scheme: scheme, Host: host} } } func withAddress(scheme, host string) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Status.Address = &duckv1.Addressable{URL: &apis.URL{ Scheme: scheme, Host: host, @@ -1397,99 +1398,99 @@ func withAddress(scheme, host string) domainMappingOption { } } -func withIngressNotConfigured(dm *v1alpha1.DomainMapping) { +func withIngressNotConfigured(dm *v1beta1.DomainMapping) { dm.Status.MarkIngressNotConfigured() } func withPropagatedStatus(status netv1alpha1.IngressStatus) domainMappingOption { - return func(r *v1alpha1.DomainMapping) { + return func(r *v1beta1.DomainMapping) { r.Status.PropagateIngressStatus(status) } } func withTLSSecret(secretName string) domainMappingOption { - return func(r *v1alpha1.DomainMapping) { - r.Spec.TLS = &v1alpha1.SecretTLS{ + return func(r *v1beta1.DomainMapping) { + r.Spec.TLS = &v1beta1.SecretTLS{ SecretName: secretName, } } } -func withCertificateNotRequired(dm *v1alpha1.DomainMapping) { - dm.Status.MarkCertificateNotRequired(v1alpha1.TLSCertificateProvidedExternally) +func withCertificateNotRequired(dm *v1beta1.DomainMapping) { + dm.Status.MarkCertificateNotRequired(v1beta1.TLSCertificateProvidedExternally) } -func withInitDomainMappingConditions(dm *v1alpha1.DomainMapping) { +func withInitDomainMappingConditions(dm *v1beta1.DomainMapping) { dm.Status.InitializeConditions() } -func withTLSNotEnabled(dm *v1alpha1.DomainMapping) { +func withTLSNotEnabled(dm *v1beta1.DomainMapping) { dm.Status.MarkTLSNotEnabled(servingv1.AutoTLSNotEnabledMessage) } -func withCertificateNotReady(dm *v1alpha1.DomainMapping) { +func withCertificateNotReady(dm *v1beta1.DomainMapping) { dm.Status.MarkCertificateNotReady(dm.Name) } -func withHTTPDowngraded(dm *v1alpha1.DomainMapping) { +func withHTTPDowngraded(dm *v1beta1.DomainMapping) { dm.Status.MarkHTTPDowngrade(dm.Name) } -func withCertificateReady(dm *v1alpha1.DomainMapping) { +func withCertificateReady(dm *v1beta1.DomainMapping) { dm.Status.MarkCertificateReady(dm.Name) } -func withCertificateFail(dm *v1alpha1.DomainMapping) { +func withCertificateFail(dm *v1beta1.DomainMapping) { dm.Status.MarkCertificateProvisionFailed(dm.Name) } -func withCertificateNotOwned(dm *v1alpha1.DomainMapping) { +func withCertificateNotOwned(dm *v1beta1.DomainMapping) { dm.Status.MarkCertificateNotOwned(dm.Name) } -func withDomainClaimNotOwned(dm *v1alpha1.DomainMapping) { +func withDomainClaimNotOwned(dm *v1beta1.DomainMapping) { dm.Status.MarkDomainClaimNotOwned() } -func withDomainClaimed(dm *v1alpha1.DomainMapping) { +func withDomainClaimed(dm *v1beta1.DomainMapping) { dm.Status.MarkDomainClaimed() } -func withReferenceResolved(dm *v1alpha1.DomainMapping) { +func withReferenceResolved(dm *v1beta1.DomainMapping) { dm.Status.MarkReferenceResolved() } func withReferenceNotResolved(message string) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Status.MarkReferenceNotResolved(message) } } func withGeneration(generation int64) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.Generation = generation } } -func withObservedGeneration(dm *v1alpha1.DomainMapping) { +func withObservedGeneration(dm *v1beta1.DomainMapping) { dm.Status.ObservedGeneration = dm.Generation } -func withFinalizer(dm *v1alpha1.DomainMapping) { +func withFinalizer(dm *v1beta1.DomainMapping) { dm.ObjectMeta.Finalizers = append(dm.ObjectMeta.Finalizers, "domainmappings.serving.knative.dev") } func withDeletionTimestamp(t *metav1.Time) domainMappingOption { - return func(dm *v1alpha1.DomainMapping) { + return func(dm *v1beta1.DomainMapping) { dm.ObjectMeta.DeletionTimestamp = t } } -func ingress(dm *v1alpha1.DomainMapping, ingressClass string, opt ...IngressOption) *netv1alpha1.Ingress { +func ingress(dm *v1beta1.DomainMapping, ingressClass string, opt ...IngressOption) *netv1alpha1.Ingress { return ingressWithChallenges(dm, ingressClass, nil /* challenges */, opt...) } -func ingressWithChallenges(dm *v1alpha1.DomainMapping, ingressClass string, challenges []netv1alpha1.HTTP01Challenge, opt ...IngressOption) *netv1alpha1.Ingress { +func ingressWithChallenges(dm *v1beta1.DomainMapping, ingressClass string, challenges []netv1alpha1.HTTP01Challenge, opt ...IngressOption) *netv1alpha1.Ingress { ing := resources.MakeIngress(dm, dm.Spec.Ref.Name, dm.Spec.Ref.Name+"."+dm.Spec.Ref.Namespace+".svc.cluster.local", ingressClass, netv1alpha1.HTTPOptionEnabled, nil /* tls */, challenges...) for _, o := range opt { o(ing) diff --git a/pkg/reconciler/testing/v1/listers.go b/pkg/reconciler/testing/v1/listers.go index 179d3b052c68..a76312dd3580 100644 --- a/pkg/reconciler/testing/v1/listers.go +++ b/pkg/reconciler/testing/v1/listers.go @@ -35,11 +35,11 @@ import ( "knative.dev/pkg/reconciler/testing" autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" v1 "knative.dev/serving/pkg/apis/serving/v1" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" fakeservingclientset "knative.dev/serving/pkg/client/clientset/versioned/fake" palisters "knative.dev/serving/pkg/client/listers/autoscaling/v1alpha1" servinglisters "knative.dev/serving/pkg/client/listers/serving/v1" - servingv1alpha1listers "knative.dev/serving/pkg/client/listers/serving/v1alpha1" + servingv1beta1listers "knative.dev/serving/pkg/client/listers/serving/v1beta1" ) var clientSetSchemes = []func(*runtime.Scheme) error{ @@ -119,8 +119,8 @@ func (l *Listers) GetRouteLister() servinglisters.RouteLister { } // GetDomainMappingLister returns a lister for DomainMapping objects. -func (l *Listers) GetDomainMappingLister() servingv1alpha1listers.DomainMappingLister { - return servingv1alpha1listers.NewDomainMappingLister(l.IndexerFor(&v1alpha1.DomainMapping{})) +func (l *Listers) GetDomainMappingLister() servingv1beta1listers.DomainMappingLister { + return servingv1beta1listers.NewDomainMappingLister(l.IndexerFor(&v1beta1.DomainMapping{})) } // GetServerlessServiceLister returns a lister for the ServerlessService objects. diff --git a/pkg/testing/v1alpha1/domainmapping.go b/pkg/testing/v1alpha1/domainmapping.go deleted file mode 100644 index 91800829d537..000000000000 --- a/pkg/testing/v1alpha1/domainmapping.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2021 The Knative 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 v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/serving/pkg/apis/serving/v1alpha1" -) - -// KReference creates a KReference which points to KService. -func KReference(namespace, name string) *duckv1.KReference { - return &duckv1.KReference{ - Namespace: namespace, - Name: name, - APIVersion: "serving.knative.dev/v1", - Kind: "Service", - } -} - -// DomainMapping creates a domainmapping with KReference. -func DomainMapping(namespace, name string, kref *duckv1.KReference) *v1alpha1.DomainMapping { - dm := &v1alpha1.DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: name, - }, - Spec: v1alpha1.DomainMappingSpec{ - Ref: *kref, - }, - } - return dm -} diff --git a/test/clients.go b/test/clients.go index e16f831637ef..5d6131d35b2d 100644 --- a/test/clients.go +++ b/test/clients.go @@ -34,7 +34,6 @@ import ( networkingv1alpha1 "knative.dev/networking/pkg/client/clientset/versioned/typed/networking/v1alpha1" "knative.dev/serving/pkg/client/clientset/versioned" servingv1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1" - servingv1alpha1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" servingv1beta1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1beta1" // Every E2E test requires this, so add it here. @@ -43,18 +42,12 @@ import ( // Clients holds instances of interfaces for making requests to Knative Serving. type Clients struct { - KubeClient kubernetes.Interface - ServingAlphaClient *ServingAlphaClients - ServingBetaClient *ServingBetaClients - ServingClient *ServingClients - NetworkingClient *NetworkingClients - Dynamic dynamic.Interface - Apiextensions *apiextensionsv1.ApiextensionsV1Client -} - -// ServingAlphaClients holds instances of interfaces for making requests to knative serving clients. -type ServingAlphaClients struct { - DomainMappings servingv1alpha1.DomainMappingInterface + KubeClient kubernetes.Interface + ServingBetaClient *ServingBetaClients + ServingClient *ServingClients + NetworkingClient *NetworkingClients + Dynamic dynamic.Interface + Apiextensions *apiextensionsv1.ApiextensionsV1Client } // ServingBetaClients holds instances of interfaces for making requests to knative serving clients. @@ -100,11 +93,6 @@ func NewClients(cfg *rest.Config, namespace string) (*Clients, error) { return nil, err } - clients.ServingAlphaClient, err = newServingAlphaClients(cfg, namespace) - if err != nil { - return nil, err - } - clients.ServingBetaClient, err = newServingBetaClients(cfg, namespace) if err != nil { return nil, err @@ -142,19 +130,6 @@ func newNetworkingClients(cfg *rest.Config, namespace string) (*NetworkingClient }, nil } -// newServingAlphaClients instantiates and returns the serving clientset required to make requests to the -// knative serving cluster. -func newServingAlphaClients(cfg *rest.Config, namespace string) (*ServingAlphaClients, error) { - cs, err := versioned.NewForConfig(cfg) - if err != nil { - return nil, err - } - - return &ServingAlphaClients{ - DomainMappings: cs.ServingV1alpha1().DomainMappings(namespace), - }, nil -} - // newServingBetaClients instantiates and returns the serving clientset required to make requests to the // knative serving cluster. func newServingBetaClients(cfg *rest.Config, namespace string) (*ServingBetaClients, error) { diff --git a/test/conformance/api/v1alpha1/domain_mapping_test.go b/test/conformance/api/v1alpha1/domain_mapping_test.go deleted file mode 100644 index 3c23dffe136e..000000000000 --- a/test/conformance/api/v1alpha1/domain_mapping_test.go +++ /dev/null @@ -1,226 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright 2020 The Knative 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 v1alpha1 - -import ( - "context" - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/wait" - duckv1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/reconciler" - pkgtest "knative.dev/pkg/test" - "knative.dev/pkg/test/spoof" - "knative.dev/serving/pkg/apis/serving/v1alpha1" - "knative.dev/serving/test" - "knative.dev/serving/test/e2e" - v1test "knative.dev/serving/test/v1" -) - -func TestDomainMapping(t *testing.T) { - if !test.ServingFlags.EnableBetaFeatures { - t.Skip("Beta features not enabled") - } - - t.Parallel() - ctx, clients := context.Background(), test.Setup(t) - - names := test.ResourceNames{ - Service: test.ObjectNameForTest(t), - Image: test.PizzaPlanet1, - } - - // Clean up on test failure or interrupt. - test.EnsureTearDown(t, clients, &names) - - // Set up initial Service. - svc, err := v1test.CreateServiceReady(t, clients, &names) - if err != nil { - t.Fatalf("Failed to create initial Service %v: %v", names.Service, err) - } - - // Using fixed hostnames can lead to conflicts when multiple tests run at - // once, so include the svc name to avoid collisions. - host := svc.Service.Name + ".example.org" - // Set resolvabledomain for custom domain to false by default. - resolvableCustomDomain := false - - if test.ServingFlags.CustomDomain != "" { - host = svc.Service.Name + "." + test.ServingFlags.CustomDomain - resolvableCustomDomain = true - } - // Point DomainMapping at our service. - var dm *v1alpha1.DomainMapping - if err := reconciler.RetryTestErrors(func(int) error { - dm, err = clients.ServingAlphaClient.DomainMappings.Create(ctx, &v1alpha1.DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: host, - Namespace: svc.Service.Namespace, - }, - Spec: v1alpha1.DomainMappingSpec{ - Ref: duckv1.KReference{ - Namespace: svc.Service.Namespace, - Name: svc.Service.Name, - APIVersion: "serving.knative.dev/v1", - Kind: "Service", - }, - }, - }, metav1.CreateOptions{}) - return err - }); err != nil { - t.Fatalf("Create(DomainMapping) = %v, expected no error", err) - } - - test.EnsureCleanup(t, func() { - clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) - }) - - // Wait for DomainMapping to go Ready. - waitErr := wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) { - var err error - dm, err = clients.ServingAlphaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{}) - if err != nil { - return true, err - } - - return dm.IsReady(), nil - }) - if waitErr != nil { - t.Fatalf("The DomainMapping %s was not marked as Ready: %v", dm.Name, waitErr) - } - - endpoint := dm.Status.URL.URL() - t.Log("Probing", endpoint) - if _, err := pkgtest.CheckEndpointState( - context.Background(), - clients.KubeClient, - t.Logf, - endpoint, - spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.PizzaPlanetText1)), - "CheckSuccessfulResponse", - resolvableCustomDomain, - test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS), - spoof.WithHeader(test.ServingFlags.RequestHeader())); err != nil { - t.Fatalf("Error probing %s: %v", endpoint, err) - } - - altClients := e2e.SetupAlternativeNamespace(t) - altNames := test.ResourceNames{ - Service: test.ObjectNameForTest(t), - Image: test.PizzaPlanet2, - } - test.EnsureTearDown(t, altClients, &altNames) - - // Set up second Service in alt namespace. - altSvc, err := v1test.CreateServiceReady(t, altClients, &altNames) - if err != nil { - t.Fatalf("Failed to create initial Service %v: %v", altNames.Service, err) - } - - // Create second domain mapping with same name in alt namespace - this will collide with the existing mapping. - var altDm *v1alpha1.DomainMapping - if err := reconciler.RetryTestErrors(func(int) error { - altDm, err = altClients.ServingAlphaClient.DomainMappings.Create(ctx, &v1alpha1.DomainMapping{ - ObjectMeta: metav1.ObjectMeta{ - Name: host, - Namespace: altSvc.Service.Namespace, - }, - Spec: v1alpha1.DomainMappingSpec{ - Ref: duckv1.KReference{ - Namespace: altSvc.Service.Namespace, - Name: altSvc.Service.Name, - APIVersion: "serving.knative.dev/v1", - Kind: "Service", - }, - }, - }, metav1.CreateOptions{}) - return err - }); err != nil { - t.Fatalf("Create(DomainMapping) = %v, expected no error", err) - } - - test.EnsureCleanup(t, func() { - altClients.ServingAlphaClient.DomainMappings.Delete(ctx, altDm.Name, metav1.DeleteOptions{}) - }) - - // Second domain mapping should go to DomainMappingConditionDomainClaimed=false state. - waitErr = wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) { - state, err := altClients.ServingAlphaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{}) - if err != nil { - return true, err - } - - return state.Generation == state.Status.ObservedGeneration && - state.Status.GetCondition(v1alpha1.DomainMappingConditionDomainClaimed).IsFalse(), nil - }) - if waitErr != nil { - t.Fatalf("The second DomainMapping %s did not enter DomainMappingConditionDomainClaimed=false state: %v", altDm.Name, waitErr) - } - - // Because the second DomainMapping collided with the first, it should not have taken effect. - t.Log("Probing", endpoint) - if _, err := pkgtest.CheckEndpointState( - context.Background(), - clients.KubeClient, - t.Logf, - endpoint, - spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.PizzaPlanetText1)), - "CheckSuccessfulResponse", - resolvableCustomDomain, - test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS), - spoof.WithHeader(test.ServingFlags.RequestHeader())); err != nil { - t.Fatalf("Error probing %s: %v", endpoint, err) - } - - // Delete the first DomainMapping. - if err := clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}); err != nil { - t.Fatalf("Delete=%v, expected no error", err) - } - - // The second DomainMapping should now be able to claim the domain. - waitErr = wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) { - var err error - altDm, err = altClients.ServingAlphaClient.DomainMappings.Get(context.Background(), altDm.Name, metav1.GetOptions{}) - if err != nil { - return true, err - } - - return altDm.IsReady(), nil - }) - if waitErr != nil { - t.Fatalf("The second DomainMapping %s was not marked as Ready: %v", dm.Name, waitErr) - } - - endpoint = altDm.Status.URL.URL() - t.Log("Probing", endpoint) - if _, err := pkgtest.CheckEndpointState( - context.Background(), - clients.KubeClient, - t.Logf, - endpoint, - spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.PizzaPlanetText2)), - "CheckSuccessfulResponse", - resolvableCustomDomain, - test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS), - spoof.WithHeader(test.ServingFlags.RequestHeader())); err != nil { - t.Fatalf("Error probing %s: %v", endpoint, err) - } -} diff --git a/test/conformance/api/v1beta1/domain_mapping_test.go b/test/conformance/api/v1beta1/domain_mapping_test.go index da1e6a4cab0c..00df41f75e32 100644 --- a/test/conformance/api/v1beta1/domain_mapping_test.go +++ b/test/conformance/api/v1beta1/domain_mapping_test.go @@ -90,7 +90,7 @@ func TestDomainMapping(t *testing.T) { } test.EnsureCleanup(t, func() { - clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) + clients.ServingBetaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) }) // Wait for DomainMapping to go Ready. @@ -158,12 +158,12 @@ func TestDomainMapping(t *testing.T) { } test.EnsureCleanup(t, func() { - altClients.ServingAlphaClient.DomainMappings.Delete(ctx, altDm.Name, metav1.DeleteOptions{}) + altClients.ServingBetaClient.DomainMappings.Delete(ctx, altDm.Name, metav1.DeleteOptions{}) }) // Second domain mapping should go to DomainMappingConditionDomainClaimed=false state. waitErr = wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) { - state, err := altClients.ServingAlphaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{}) + state, err := altClients.ServingBetaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{}) if err != nil { return true, err } @@ -191,7 +191,7 @@ func TestDomainMapping(t *testing.T) { } // Delete the first DomainMapping. - if err := clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}); err != nil { + if err := clients.ServingBetaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}); err != nil { t.Fatalf("Delete=%v, expected no error", err) } diff --git a/test/e2e/autotls/domain_mapping_test.go b/test/e2e/autotls/domain_mapping_test.go index 8fe04f96f5ba..47f22a94b7bc 100644 --- a/test/e2e/autotls/domain_mapping_test.go +++ b/test/e2e/autotls/domain_mapping_test.go @@ -29,7 +29,7 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/pkg/reconciler" v1 "knative.dev/serving/pkg/apis/serving/v1" - "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" "knative.dev/serving/test" v1test "knative.dev/serving/test/v1" ) @@ -96,14 +96,14 @@ func TestDomainMappingAutoTLS(t *testing.T) { host := "dm." + suffix // Point DomainMapping at our service. - var dm *v1alpha1.DomainMapping + var dm *v1beta1.DomainMapping if err := reconciler.RetryTestErrors(func(int) error { - dm, err = clients.ServingAlphaClient.DomainMappings.Create(ctx, &v1alpha1.DomainMapping{ + dm, err = clients.ServingBetaClient.DomainMappings.Create(ctx, &v1beta1.DomainMapping{ ObjectMeta: metav1.ObjectMeta{ Name: host, Namespace: svc.Service.Namespace, }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ Namespace: svc.Service.Namespace, Name: svc.Service.Name, @@ -118,12 +118,12 @@ func TestDomainMappingAutoTLS(t *testing.T) { } test.EnsureCleanup(t, func() { - clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) + clients.ServingBetaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) }) // Wait for DomainMapping to go Ready. if waitErr := wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) { - state, err := clients.ServingAlphaClient.DomainMappings.Get(ctx, dm.Name, metav1.GetOptions{}) + state, err := clients.ServingBetaClient.DomainMappings.Get(ctx, dm.Name, metav1.GetOptions{}) // DomainMapping can go Ready if only http is available. // Hence the checking for the URL scheme to make sure it is ready for https diff --git a/test/e2e/domainmapping/domain_mapping_test.go b/test/e2e/domainmapping/domain_mapping_test.go index 4556b6f77c22..1e129f0937f8 100644 --- a/test/e2e/domainmapping/domain_mapping_test.go +++ b/test/e2e/domainmapping/domain_mapping_test.go @@ -44,6 +44,7 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" pkgTest "knative.dev/pkg/test" "knative.dev/serving/pkg/apis/serving/v1alpha1" + "knative.dev/serving/pkg/apis/serving/v1beta1" "knative.dev/serving/test" v1test "knative.dev/serving/test/v1" ) @@ -102,35 +103,35 @@ func TestBYOCertificate(t *testing.T) { } }) - dm := v1alpha1.DomainMapping{ + dm := v1beta1.DomainMapping{ TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: host, Namespace: ksvc.Service.Namespace, }, - Spec: v1alpha1.DomainMappingSpec{ + Spec: v1beta1.DomainMappingSpec{ Ref: duckv1.KReference{ APIVersion: "serving.knative.dev/v1", Name: ksvc.Service.Name, Namespace: ksvc.Service.Namespace, Kind: "Service", }, - TLS: &v1alpha1.SecretTLS{ + TLS: &v1beta1.SecretTLS{ SecretName: secret.Name, }}, - Status: v1alpha1.DomainMappingStatus{}, + Status: v1beta1.DomainMappingStatus{}, } - _, err = clients.ServingAlphaClient.DomainMappings.Create(ctx, &dm, metav1.CreateOptions{}) + _, err = clients.ServingBetaClient.DomainMappings.Create(ctx, &dm, metav1.CreateOptions{}) if err != nil { t.Fatalf("Problem creating DomainMapping %q: %v", host, err) } test.EnsureCleanup(t, func() { - clients.ServingAlphaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) + clients.ServingBetaClient.DomainMappings.Delete(ctx, dm.Name, metav1.DeleteOptions{}) }) err = wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) { - dm, err := clients.ServingAlphaClient.DomainMappings.Get(ctx, dm.Name, metav1.GetOptions{}) + dm, err := clients.ServingBetaClient.DomainMappings.Get(ctx, dm.Name, metav1.GetOptions{}) if err != nil { return false, err } diff --git a/vendor/k8s.io/code-generator/generate-groups.sh b/vendor/k8s.io/code-generator/generate-groups.sh old mode 100644 new mode 100755 diff --git a/vendor/knative.dev/pkg/hack/generate-knative.sh b/vendor/knative.dev/pkg/hack/generate-knative.sh old mode 100644 new mode 100755