sigs.k8s.io/cluster-api-provider-azure@v1.14.3/util/futures/getter.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 futures 18 19 import ( 20 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" 21 "sigs.k8s.io/controller-runtime/pkg/client" 22 ) 23 24 // Getter interface defines methods that an object should implement in order to 25 // use the futures package for getting long running operation states. 26 type Getter interface { 27 client.Object 28 29 // GetFutures returns the list of long running operation states for an object. 30 GetFutures() infrav1.Futures 31 } 32 33 // Get returns the future with the given name, if the future does not exists, 34 // it returns nil. 35 func Get(from Getter, name, service, futureType string) *infrav1.Future { 36 futures := from.GetFutures() 37 if futures == nil { 38 return nil 39 } 40 41 for _, f := range futures { 42 if f.Name == name && f.ServiceName == service && f.Type == futureType { 43 return &f 44 } 45 } 46 return nil 47 } 48 49 // Has returns true if a future with the given name exists. 50 func Has(from Getter, name, service, futureType string) bool { 51 return Get(from, name, service, futureType) != nil 52 }