knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/duck/v1/binding_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 v1
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  	"k8s.io/apimachinery/pkg/runtime"
    22  
    23  	"knative.dev/pkg/apis"
    24  	"knative.dev/pkg/apis/duck"
    25  	"knative.dev/pkg/tracker"
    26  )
    27  
    28  // +genduck
    29  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    30  
    31  // Binding is a duck type that specifies the partial schema to which all
    32  // Binding implementations should adhere.
    33  type Binding struct {
    34  	metav1.TypeMeta   `json:",inline"`
    35  	metav1.ObjectMeta `json:"metadata,omitempty"`
    36  
    37  	Spec BindingSpec `json:"spec"`
    38  }
    39  
    40  // Verify that Binding implements the appropriate interfaces.
    41  var (
    42  	_ duck.Implementable = (*Binding)(nil)
    43  	_ duck.Populatable   = (*Binding)(nil)
    44  	_ apis.Listable      = (*Binding)(nil)
    45  )
    46  
    47  // BindingSpec specifies the spec portion of the Binding partial-schema.
    48  type BindingSpec struct {
    49  	// Subject references the resource(s) whose "runtime contract" should be
    50  	// augmented by Binding implementations.
    51  	Subject tracker.Reference `json:"subject"`
    52  }
    53  
    54  // GetFullType implements duck.Implementable
    55  func (*Binding) GetFullType() duck.Populatable {
    56  	return &Binding{}
    57  }
    58  
    59  // Populate implements duck.Populatable
    60  func (t *Binding) Populate() {
    61  	t.Spec = BindingSpec{
    62  		Subject: tracker.Reference{
    63  			APIVersion: "apps/v1",
    64  			Kind:       "Deployment",
    65  			Namespace:  "default",
    66  			// Name and Selector are mutually exclusive,
    67  			// but we fill them both in for this test.
    68  			Name: "bazinga",
    69  			Selector: &metav1.LabelSelector{
    70  				MatchLabels: map[string]string{
    71  					"foo": "bar",
    72  					"baz": "blah",
    73  				},
    74  			},
    75  		},
    76  	}
    77  }
    78  
    79  // GetListType implements apis.Listable
    80  func (*Binding) GetListType() runtime.Object {
    81  	return &BindingList{}
    82  }
    83  
    84  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    85  
    86  // BindingList is a list of Binding resources
    87  type BindingList struct {
    88  	metav1.TypeMeta `json:",inline"`
    89  	metav1.ListMeta `json:"metadata"`
    90  
    91  	Items []Binding `json:"items"`
    92  }