github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/blockaffinity.go (about)

     1  // Copyright (c) 2022 Tigera, Inc. All rights reserved.
     2  
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package v3
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  )
    20  
    21  const (
    22  	KindBlockAffinity     = "BlockAffinity"
    23  	KindBlockAffinityList = "BlockAffinityList"
    24  )
    25  
    26  type BlockAffinityState string
    27  
    28  const (
    29  	StateConfirmed       BlockAffinityState = "confirmed"
    30  	StatePending         BlockAffinityState = "pending"
    31  	StatePendingDeletion BlockAffinityState = "pendingDeletion"
    32  )
    33  
    34  // +genclient
    35  // +genclient:nonNamespaced
    36  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    37  
    38  // BlockAffinity maintains a block affinity's state
    39  type BlockAffinity struct {
    40  	metav1.TypeMeta `json:",inline"`
    41  	// Standard object's metadata.
    42  	metav1.ObjectMeta `json:"metadata,omitempty"`
    43  	// Specification of the BlockAffinity.
    44  	Spec BlockAffinitySpec `json:"spec,omitempty"`
    45  }
    46  
    47  // BlockAffinitySpec contains the specification for a BlockAffinity resource.
    48  type BlockAffinitySpec struct {
    49  	// The state of the block affinity with regard to any referenced IPAM blocks.
    50  	State BlockAffinityState `json:"state"`
    51  
    52  	// The node that this block affinity is assigned to.
    53  	Node string `json:"node"`
    54  
    55  	// The CIDR range this block affinity references.
    56  	CIDR string `json:"cidr"`
    57  
    58  	// Deleted indicates whether or not this block affinity is disabled and is
    59  	// used as part of race-condition prevention. When set to true, clients
    60  	// should treat this block as if it does not exist.
    61  	Deleted bool `json:"deleted,omitempty"`
    62  }
    63  
    64  // +genclient:nonNamespaced
    65  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    66  
    67  // BlockAffinityList contains a list of BlockAffinity resources.
    68  type BlockAffinityList struct {
    69  	metav1.TypeMeta `json:",inline"`
    70  	metav1.ListMeta `json:"metadata"`
    71  	Items           []BlockAffinity `json:"items"`
    72  }
    73  
    74  // NewBlockAffinity creates a new (zeroed) BlockAffinity struct with the TypeMetadata initialised to the current
    75  // version.
    76  func NewBlockAffinity() *BlockAffinity {
    77  	return &BlockAffinity{
    78  		TypeMeta: metav1.TypeMeta{
    79  			Kind:       KindBlockAffinity,
    80  			APIVersion: GroupVersionCurrent,
    81  		},
    82  	}
    83  }
    84  
    85  // NewBlockAffinityList creates a new (zeroed) BlockAffinityList struct with the TypeMetadata initialised to the current
    86  // version.
    87  func NewBlockAffinityList() *BlockAffinityList {
    88  	return &BlockAffinityList{
    89  		TypeMeta: metav1.TypeMeta{
    90  			Kind:       KindBlockAffinityList,
    91  			APIVersion: GroupVersionCurrent,
    92  		},
    93  	}
    94  }