@@ -24,10 +24,7 @@ import (
2424
2525 "github.com/codefresh-io/venona/venonactl/pkg/store"
2626
27- "github.com/codefresh-io/venona/venonactl/internal"
28-
29- "github.com/codefresh-io/venona/venonactl/pkg/codefresh"
30- runtimectl "github.com/codefresh-io/venona/venonactl/pkg/operators"
27+ "github.com/codefresh-io/venona/venonactl/pkg/plugins"
3128 "github.com/spf13/cobra"
3229 "github.com/spf13/viper"
3330)
@@ -61,6 +58,16 @@ var installCmd = &cobra.Command{
6158 extendStoreWithCodefershClient ()
6259 extendStoreWithKubeClient ()
6360
61+ builder := plugins .NewBuilder ()
62+ builderInstallOpt := & plugins.InstallOptions {
63+ CodefreshHost : s .CodefreshAPI .Host ,
64+ CodefreshToken : s .CodefreshAPI .Token ,
65+ ClusterNamespace : s .KubernetesAPI .Namespace ,
66+ MarkAsDefault : installCmdOptions .setDefaultRuntime ,
67+ StorageClass : installCmdOptions .storageClass ,
68+ IsDefaultStorageClass : isUsingDefaultStorageClass (installCmdOptions .storageClass ),
69+ }
70+
6471 if installCmdOptions .kube .context == "" {
6572 config := clientcmd .GetConfigFromFileOrDie (s .KubernetesAPI .ConfigPath )
6673 installCmdOptions .kube .context = config .CurrentContext
@@ -91,27 +98,40 @@ var installCmd = &cobra.Command{
9198 }
9299 s .ClusterInCodefresh = installCmdOptions .clusterNameInCodefresh
93100 if installCmdOptions .installOnlyRuntimeEnvironment == true && installCmdOptions .skipRuntimeInstallation == true {
94- internal . DieOnError (fmt .Errorf ("Cannot use both flags skip-runtime-installation and only-runtime-environment" ))
101+ dieOnError (fmt .Errorf ("Cannot use both flags skip-runtime-installation and only-runtime-environment" ))
95102 }
96103 if installCmdOptions .installOnlyRuntimeEnvironment == true {
97- registerRuntimeEnvironment ()
98- return
104+ builder .Add (plugins .RuntimeEnvironmentPluginType )
99105 } else if installCmdOptions .skipRuntimeInstallation == true {
100106 if installCmdOptions .runtimeEnvironmentName == "" {
101- internal . DieOnError (fmt .Errorf ("runtime-environment flag is required when using flag skip-runtime-installation" ))
107+ dieOnError (fmt .Errorf ("runtime-environment flag is required when using flag skip-runtime-installation" ))
102108 }
103109 s .RuntimeEnvironment = installCmdOptions .runtimeEnvironmentName
104110 logrus .Info ("Skipping installation of runtime environment, installing venona only" )
105- installvenona ( )
111+ builder . Add ( plugins . VenonaPluginType )
106112 } else {
107- registerRuntimeEnvironment ()
108- installvenona ()
113+ builder .
114+ Add (plugins .RuntimeEnvironmentPluginType ).
115+ Add (plugins .VenonaPluginType )
109116 }
110117 if isUsingDefaultStorageClass (installCmdOptions .storageClass ) {
111- configureVolumeProvisioner ( )
118+ builder . Add ( plugins . VolumeProvisionerPluginType )
112119 } else {
113120 logrus .Info ("Non default StorageClass is set, skipping installation of volume provisioner" )
114121 }
122+
123+ builderInstallOpt .ClusterName = s .KubernetesAPI .ContextName
124+ builderInstallOpt .RegisterWithAgent = true
125+ if s .ClusterInCodefresh != "" {
126+ builderInstallOpt .ClusterName = s .ClusterInCodefresh
127+ builderInstallOpt .RegisterWithAgent = false
128+ }
129+
130+ for _ , p := range builder .Get () {
131+ if err := p .Install (builderInstallOpt ); err != nil {
132+ dieOnError (err )
133+ }
134+ }
115135 logrus .Info ("Installation completed Successfully\n " )
116136 },
117137}
@@ -135,49 +155,3 @@ func init() {
135155 installCmd .Flags ().BoolVar (& installCmdOptions .dryRun , "dry-run" , false , "Set to true to simulate installation" )
136156 installCmd .Flags ().BoolVar (& installCmdOptions .setDefaultRuntime , "set-default" , false , "Mark the install runtime-environment as default one after installation" )
137157}
138-
139- func registerRuntimeEnvironment () {
140- s := store .GetStore ()
141- registerWithAgent := true
142- name := s .KubernetesAPI .ContextName
143- if s .ClusterInCodefresh != "" {
144- registerWithAgent = false
145- name = s .ClusterInCodefresh
146- }
147- opt := & codefresh.APIOptions {
148- Logger : logrus .New (),
149- CodefreshHost : s .CodefreshAPI .Host ,
150- CodefreshToken : s .CodefreshAPI .Token ,
151- ClusterName : name ,
152- ClusterNamespace : s .KubernetesAPI .Namespace ,
153- RegisterWithAgent : registerWithAgent ,
154- MarkAsDefault : installCmdOptions .setDefaultRuntime ,
155- StorageClass : installCmdOptions .storageClass ,
156- IsDefaultStorageClass : isUsingDefaultStorageClass (installCmdOptions .storageClass ),
157- }
158- cf := codefresh .NewCodefreshAPI (opt )
159-
160- cert , err := cf .Sign ()
161- internal .DieOnError (err )
162- err = cf .Validate ()
163- internal .DieOnError (err )
164-
165- err = runtimectl .GetOperator (runtimectl .RuntimeEnvironmentOperatorType ).Install ()
166- internal .DieOnError (err )
167-
168- re , err := cf .Register ()
169- internal .DieOnError (err )
170-
171- s .RuntimeEnvironment = re .Metadata .Name
172- s .ServerCert = cert
173- }
174-
175- func installvenona () {
176- err := runtimectl .GetOperator (runtimectl .VenonaOperatorType ).Install ()
177- internal .DieOnError (err )
178- }
179-
180- func configureVolumeProvisioner () {
181- err := runtimectl .GetOperator (runtimectl .VolumeProvisionerOperatorType ).Install ()
182- internal .DieOnError (err )
183- }
0 commit comments