github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/clusterfile/clusterfile.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 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 clusterfile 16 17 import ( 18 "errors" 19 "sync" 20 21 "github.com/alibaba/sealer/pkg/runtime" 22 v1 "github.com/alibaba/sealer/types/api/v1" 23 v2 "github.com/alibaba/sealer/types/api/v2" 24 ) 25 26 var ErrTypeNotFound = errors.New("no corresponding type structure was found") 27 28 type ClusterFile struct { 29 path string 30 Cluster v2.Cluster 31 Configs []v1.Config 32 KubeConfig *runtime.KubeadmConfig 33 Plugins []v1.Plugin 34 } 35 36 var ( 37 clusterFile = &ClusterFile{} 38 once sync.Once 39 ) 40 41 type Interface interface { 42 PreProcessor 43 GetCluster() v2.Cluster 44 GetConfigs() []v1.Config 45 GetPlugins() []v1.Plugin 46 GetKubeadmConfig() *runtime.KubeadmConfig 47 } 48 49 func (c *ClusterFile) GetCluster() v2.Cluster { 50 return c.Cluster 51 } 52 53 func (c *ClusterFile) GetConfigs() []v1.Config { 54 return c.Configs 55 } 56 57 func (c *ClusterFile) GetPlugins() []v1.Plugin { 58 return c.Plugins 59 } 60 61 func (c *ClusterFile) GetKubeadmConfig() *runtime.KubeadmConfig { 62 return c.KubeConfig 63 } 64 65 func NewClusterFile(path string) (i Interface, err error) { 66 if path == "" { 67 return clusterFile, nil 68 } 69 once.Do(func() { 70 clusterFile.path = path 71 err = clusterFile.Process() 72 }) 73 return clusterFile, err 74 }