github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/preflight/concat_spec.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package preflight 21 22 import ( 23 troubleshoot "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" 24 25 preflightv1beta2 "github.com/1aal/kubeblocks/externalapis/preflight/v1beta2" 26 ) 27 28 // ConcatPreflightSpec splices multiple PreflightSpec into one Preflight object 29 func ConcatPreflightSpec(target *preflightv1beta2.Preflight, source *preflightv1beta2.Preflight) *preflightv1beta2.Preflight { 30 if source == nil { 31 return target 32 } 33 var newSpec *preflightv1beta2.Preflight 34 if target == nil { 35 newSpec = source 36 } else { 37 newSpec = target.DeepCopy() 38 newSpec.Spec.Collectors = append(newSpec.Spec.Collectors, source.Spec.Collectors...) 39 newSpec.Spec.RemoteCollectors = append(newSpec.Spec.RemoteCollectors, source.Spec.RemoteCollectors...) 40 newSpec.Spec.Analyzers = append(newSpec.Spec.Analyzers, source.Spec.Analyzers...) 41 newSpec.Spec.ExtendCollectors = append(newSpec.Spec.ExtendCollectors, source.Spec.ExtendCollectors...) 42 newSpec.Spec.ExtendAnalyzers = append(newSpec.Spec.ExtendAnalyzers, source.Spec.ExtendAnalyzers...) 43 } 44 return newSpec 45 } 46 47 // ConcatHostPreflightSpec splices multiple HostPreflightSpec into one HostPreflight object 48 func ConcatHostPreflightSpec(target *preflightv1beta2.HostPreflight, source *preflightv1beta2.HostPreflight) *preflightv1beta2.HostPreflight { 49 if source == nil { 50 return target 51 } 52 var newSpec *preflightv1beta2.HostPreflight 53 if target == nil { 54 newSpec = source 55 } else { 56 newSpec = target.DeepCopy() 57 newSpec.Spec.Collectors = append(newSpec.Spec.Collectors, source.Spec.Collectors...) 58 newSpec.Spec.RemoteCollectors = append(newSpec.Spec.RemoteCollectors, source.Spec.RemoteCollectors...) 59 newSpec.Spec.Analyzers = append(newSpec.Spec.Analyzers, source.Spec.Analyzers...) 60 newSpec.Spec.ExtendCollectors = append(newSpec.Spec.ExtendCollectors, source.Spec.ExtendCollectors...) 61 newSpec.Spec.ExtendAnalyzers = append(newSpec.Spec.ExtendAnalyzers, source.Spec.ExtendAnalyzers...) 62 } 63 return newSpec 64 } 65 66 // ExtractHostPreflightSpec extracts spec of troubleshootv1beta2.HostPreflight from preflightv1beta2.HostPreflight 67 func ExtractHostPreflightSpec(kb *preflightv1beta2.HostPreflight) *troubleshoot.HostPreflight { 68 if kb != nil { 69 return &troubleshoot.HostPreflight{ 70 TypeMeta: kb.TypeMeta, 71 ObjectMeta: kb.ObjectMeta, 72 Spec: troubleshoot.HostPreflightSpec{ 73 Collectors: kb.Spec.Collectors, 74 RemoteCollectors: kb.Spec.RemoteCollectors, 75 Analyzers: kb.Spec.Analyzers, 76 }, 77 } 78 } 79 return nil 80 }