sigs.k8s.io/cluster-api@v1.7.1/cmd/clusterctl/client/alpha/client.go (about) 1 /* 2 Copyright 2020 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 alpha 18 19 // Client is the alpha client. 20 type Client interface { 21 Rollout() Rollout 22 } 23 24 // alphaClient implements Client. 25 type alphaClient struct { 26 rollout Rollout 27 } 28 29 // ensure alphaClient implements Client. 30 var _ Client = &alphaClient{} 31 32 // Option is a configuration option supplied to New. 33 type Option func(*alphaClient) 34 35 // InjectRollout allows to override the rollout implementation to use. 36 func InjectRollout(rollout Rollout) Option { 37 return func(c *alphaClient) { 38 c.rollout = rollout 39 } 40 } 41 42 // New returns a Client. 43 func New(options ...Option) Client { 44 return newAlphaClient(options...) 45 } 46 47 func newAlphaClient(options ...Option) *alphaClient { 48 client := &alphaClient{} 49 for _, o := range options { 50 o(client) 51 } 52 53 // if there is an injected rollout, use it, otherwise use a default one 54 if client.rollout == nil { 55 client.rollout = newRolloutClient() 56 } 57 58 return client 59 } 60 61 func (c *alphaClient) Rollout() Rollout { 62 return c.rollout 63 }