knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/test/example/v1alpha1/foo_types.go (about) 1 /* 2 Copyright 2020 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 v1alpha1 18 19 import ( 20 "context" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 "k8s.io/apimachinery/pkg/runtime/schema" 24 "knative.dev/pkg/apis" 25 duckv1 "knative.dev/pkg/apis/duck/v1" 26 "knative.dev/pkg/kmeta" 27 ) 28 29 // +genclient 30 // +genreconciler 31 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 32 33 // Foo is for testing. 34 type Foo struct { 35 metav1.TypeMeta `json:",inline"` 36 // +optional 37 metav1.ObjectMeta `json:"metadata,omitempty"` 38 39 // Spec holds the desired state of the Foo (from the client). 40 // +optional 41 Spec FooSpec `json:"spec,omitempty"` 42 43 // Status communicates the observed state of the Foo (from the controller). 44 // +optional 45 Status FooStatus `json:"status,omitempty"` 46 } 47 48 // Check that Foo can be validated and defaulted. 49 var ( 50 _ apis.Validatable = (*Foo)(nil) 51 _ apis.Defaultable = (*Foo)(nil) 52 _ kmeta.OwnerRefable = (*Foo)(nil) 53 _ duckv1.KRShaped = (*Foo)(nil) 54 ) 55 56 // FooSpec holds the desired state of the Foo (from the client). 57 type FooSpec struct{} 58 59 // FooStatus communicates the observed state of the Foo (from the controller). 60 type FooStatus struct { 61 duckv1.Status `json:",inline"` 62 } 63 64 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 65 66 // FooList is a list of Foo resources 67 type FooList struct { 68 metav1.TypeMeta `json:",inline"` 69 metav1.ListMeta `json:"metadata"` 70 71 Items []Foo `json:"items"` 72 } 73 74 // -- lifecycle -- 75 76 func (fs *FooStatus) InitializeConditions() {} 77 78 // GetGroupVersionKind implements kmeta.OwnerRefable 79 func (f *Foo) GetGroupVersionKind() schema.GroupVersionKind { 80 return SchemeGroupVersion.WithKind("Bar") 81 } 82 83 // -- Defaults -- 84 85 // SetDefaults implements apis.Defaultable 86 func (f *Foo) SetDefaults(ctx context.Context) { 87 // Nothing to default. 88 } 89 90 // -- Validation -- 91 92 // Validate implements apis.Validatable 93 func (f *Foo) Validate(ctx context.Context) *apis.FieldError { 94 // Nothing to validate. 95 return nil 96 } 97 98 // GetStatus retrieves the status of the Foo Implements the KRShaped interface. 99 func (f *Foo) GetStatus() *duckv1.Status { 100 return &f.Status.Status 101 } 102 103 // GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. 104 func (*Foo) GetConditionSet() apis.ConditionSet { 105 return apis.NewLivingConditionSet() 106 }