sigs.k8s.io/cluster-api@v1.7.1/exp/topology/scope/scope.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 scope 18 19 import ( 20 "strconv" 21 22 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 23 ) 24 25 // Scope holds all the information to process a request in the topology/ClusterReconciler controller. 26 type Scope struct { 27 // Blueprint holds all the objects required for computing the desired state of a managed topology. 28 Blueprint *ClusterBlueprint 29 30 // Current holds the current state of the managed topology. 31 Current *ClusterState 32 33 // Desired holds the desired state of the managed topology. 34 Desired *ClusterState 35 36 // UpgradeTracker holds information about ongoing upgrades in the managed topology. 37 UpgradeTracker *UpgradeTracker 38 39 // HookResponseTracker holds the hook responses that will be used to 40 // calculate a combined reconcile result. 41 HookResponseTracker *HookResponseTracker 42 } 43 44 // New returns a new Scope with only the cluster; while processing a request in the topology/ClusterReconciler controller 45 // additional information will be added about the Cluster blueprint, current state and desired state. 46 func New(cluster *clusterv1.Cluster) *Scope { 47 // enforce TypeMeta values in the Cluster object so we can assume it is always set during reconciliation. 48 cluster.APIVersion = clusterv1.GroupVersion.String() 49 cluster.Kind = "Cluster" 50 51 // Determine the maximum upgrade concurrency from the annotation on the cluster. 52 maxMDUpgradeConcurrency := 1 53 maxMPUpgradeConcurrency := 1 54 if concurrency, ok := cluster.Annotations[clusterv1.ClusterTopologyUpgradeConcurrencyAnnotation]; ok { 55 // The error can be ignored because the webhook ensures that the value is a positive integer. 56 maxMDUpgradeConcurrency, _ = strconv.Atoi(concurrency) 57 maxMPUpgradeConcurrency, _ = strconv.Atoi(concurrency) 58 } 59 return &Scope{ 60 Blueprint: &ClusterBlueprint{}, 61 Current: &ClusterState{ 62 Cluster: cluster, 63 }, 64 UpgradeTracker: NewUpgradeTracker( 65 MaxMDUpgradeConcurrency(maxMDUpgradeConcurrency), 66 MaxMPUpgradeConcurrency(maxMPUpgradeConcurrency), 67 ), 68 HookResponseTracker: NewHookResponseTracker(), 69 } 70 }