sigs.k8s.io/cluster-api@v1.7.1/internal/contract/controlplane_template.go (about) 1 /* 2 Copyright 2021 The Kubernetes 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 contract 18 19 import "sync" 20 21 // ControlPlaneTemplateContract encodes information about the Cluster API contract for ControlPlaneTemplate objects 22 // like e.g. the KubeadmControlPlane etc. 23 type ControlPlaneTemplateContract struct{} 24 25 var controlPlaneTemplate *ControlPlaneTemplateContract 26 var onceControlPlaneTemplate sync.Once 27 28 // ControlPlaneTemplate provide access to the information about the Cluster API contract for ControlPlaneTemplate objects. 29 func ControlPlaneTemplate() *ControlPlaneTemplateContract { 30 onceControlPlaneTemplate.Do(func() { 31 controlPlaneTemplate = &ControlPlaneTemplateContract{} 32 }) 33 return controlPlaneTemplate 34 } 35 36 // InfrastructureMachineTemplate provide access to InfrastructureMachineTemplate reference, if any. 37 // NOTE: When working with unstructured there is no way to understand if the ControlPlane provider 38 // do support a field in the type definition from the fact that a field is not set in a given instance. 39 // This is why in we are deriving if this field is required from the ClusterClass in the topology reconciler code. 40 func (c *ControlPlaneTemplateContract) InfrastructureMachineTemplate() *Ref { 41 return &Ref{ 42 path: Path{"spec", "template", "spec", "machineTemplate", "infrastructureRef"}, 43 } 44 } 45 46 // Template provides access to the template. 47 func (c *ControlPlaneTemplateContract) Template() *ControlPlaneTemplateTemplate { 48 return &ControlPlaneTemplateTemplate{} 49 } 50 51 // ControlPlaneTemplateTemplate provides a helper struct for working with the template in an ControlPlaneTemplate. 52 type ControlPlaneTemplateTemplate struct{} 53 54 // Metadata provides access to the metadata of a template. 55 func (c *ControlPlaneTemplateTemplate) Metadata() *Metadata { 56 return &Metadata{ 57 path: Path{"spec", "template", "metadata"}, 58 } 59 } 60 61 // MachineTemplate provides access to MachineTemplate in a ControlPlaneTemplate object, if any. 62 func (c *ControlPlaneTemplateTemplate) MachineTemplate() *ControlPlaneTemplateMachineTemplate { 63 return &ControlPlaneTemplateMachineTemplate{} 64 } 65 66 // ControlPlaneTemplateMachineTemplate provides a helper struct for working with MachineTemplate. 67 type ControlPlaneTemplateMachineTemplate struct{} 68 69 // Metadata provides access to the metadata of the MachineTemplate of a ControlPlaneTemplate. 70 func (c *ControlPlaneTemplateMachineTemplate) Metadata() *Metadata { 71 return &Metadata{ 72 path: Path{"spec", "template", "spec", "machineTemplate", "metadata"}, 73 } 74 } 75 76 // NodeDrainTimeout provides access to the nodeDrainTimeout of a MachineTemplate. 77 func (c *ControlPlaneTemplateMachineTemplate) NodeDrainTimeout() *Duration { 78 return &Duration{ 79 path: Path{"spec", "template", "spec", "machineTemplate", "nodeDrainTimeout"}, 80 } 81 } 82 83 // NodeVolumeDetachTimeout provides access to the nodeVolumeDetachTimeout of a MachineTemplate. 84 func (c *ControlPlaneTemplateMachineTemplate) NodeVolumeDetachTimeout() *Duration { 85 return &Duration{ 86 path: Path{"spec", "template", "spec", "machineTemplate", "nodeVolumeDetachTimeout"}, 87 } 88 } 89 90 // NodeDeletionTimeout provides access to the nodeDeletionTimeout of a MachineTemplate. 91 func (c *ControlPlaneTemplateMachineTemplate) NodeDeletionTimeout() *Duration { 92 return &Duration{ 93 path: Path{"spec", "template", "spec", "machineTemplate", "nodeDeletionTimeout"}, 94 } 95 }