knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/duck/v1/addressable_types.go (about) 1 /* 2 Copyright 2019 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1 18 19 import ( 20 "context" 21 "fmt" 22 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 "k8s.io/apimachinery/pkg/runtime" 25 "k8s.io/apimachinery/pkg/runtime/schema" 26 27 "knative.dev/pkg/apis" 28 "knative.dev/pkg/apis/duck/ducktypes" 29 "knative.dev/pkg/kmeta" 30 ) 31 32 // +genduck 33 34 // Addressable provides a generic mechanism for a custom resource 35 // definition to indicate a destination for message delivery. 36 // 37 // Addressable is the schema for the destination information. This is 38 // typically stored in the object's `status`, as this information may 39 // be generated by the controller. 40 type Addressable struct { 41 // Name is the name of the address. 42 // +optional 43 Name *string `json:"name,omitempty"` 44 45 URL *apis.URL `json:"url,omitempty"` 46 47 // CACerts is the Certification Authority (CA) certificates in PEM format 48 // according to https://www.rfc-editor.org/rfc/rfc7468. 49 // +optional 50 CACerts *string `json:"CACerts,omitempty"` 51 52 // Audience is the OIDC audience for this address. 53 // +optional 54 Audience *string `json:"audience,omitempty"` 55 } 56 57 // Addressable is a Convertible type. 58 var _ apis.Convertible = (*Addressable)(nil) 59 60 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 61 62 // AddressableType is a skeleton type wrapping Addressable in the manner we expect 63 // resource writers defining compatible resources to embed it. We will 64 // typically use this type to deserialize Addressable ObjectReferences and 65 // access the Addressable data. This is not a real resource. 66 type AddressableType struct { 67 metav1.TypeMeta `json:",inline"` 68 metav1.ObjectMeta `json:"metadata,omitempty"` 69 70 Status AddressStatus `json:"status"` 71 } 72 73 // AddressStatus shows how we expect folks to embed Addressable in 74 // their Status field. 75 type AddressStatus struct { 76 // Address is a single Addressable address. 77 // If Addresses is present, Address will be ignored by clients. 78 // +optional 79 Address *Addressable `json:"address,omitempty"` 80 81 // Addresses is a list of addresses for different protocols (HTTP and HTTPS) 82 // If Addresses is present, Address must be ignored by clients. 83 // +optional 84 Addresses []Addressable `json:"addresses,omitempty"` 85 } 86 87 // Verify AddressableType resources meet duck contracts. 88 var ( 89 _ apis.Listable = (*AddressableType)(nil) 90 _ ducktypes.Populatable = (*AddressableType)(nil) 91 _ kmeta.OwnerRefable = (*AddressableType)(nil) 92 ) 93 94 // GetFullType implements duck.Implementable 95 func (*Addressable) GetFullType() ducktypes.Populatable { 96 return &AddressableType{} 97 } 98 99 // ConvertTo implements apis.Convertible 100 func (a *Addressable) ConvertTo(ctx context.Context, to apis.Convertible) error { 101 return fmt.Errorf("v1 is the highest known version, got: %T", to) 102 } 103 104 // ConvertFrom implements apis.Convertible 105 func (a *Addressable) ConvertFrom(ctx context.Context, from apis.Convertible) error { 106 return fmt.Errorf("v1 is the highest known version, got: %T", from) 107 } 108 109 // Populate implements duck.Populatable 110 func (t *AddressableType) Populate() { 111 name := "http" 112 t.Status = AddressStatus{ 113 Address: &Addressable{ 114 // Populate ALL fields 115 Name: &name, 116 URL: &apis.URL{ 117 Scheme: "http", 118 Host: "foo.com", 119 }, 120 }, 121 } 122 } 123 124 // GetGroupVersionKind implements kmeta.OwnerRefable 125 func (t *AddressableType) GetGroupVersionKind() schema.GroupVersionKind { 126 return t.GroupVersionKind() 127 } 128 129 // GetListType implements apis.Listable 130 func (*AddressableType) GetListType() runtime.Object { 131 return &AddressableTypeList{} 132 } 133 134 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 135 136 // AddressableTypeList is a list of AddressableType resources 137 type AddressableTypeList struct { 138 metav1.TypeMeta `json:",inline"` 139 metav1.ListMeta `json:"metadata"` 140 141 Items []AddressableType `json:"items"` 142 }