@@ -24,10 +24,7 @@ import (
24
24
25
25
"github.com/codefresh-io/venona/venonactl/pkg/store"
26
26
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"
31
28
"github.com/spf13/cobra"
32
29
"github.com/spf13/viper"
33
30
)
@@ -61,6 +58,16 @@ var installCmd = &cobra.Command{
61
58
extendStoreWithCodefershClient ()
62
59
extendStoreWithKubeClient ()
63
60
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
+
64
71
if installCmdOptions .kube .context == "" {
65
72
config := clientcmd .GetConfigFromFileOrDie (s .KubernetesAPI .ConfigPath )
66
73
installCmdOptions .kube .context = config .CurrentContext
@@ -91,27 +98,40 @@ var installCmd = &cobra.Command{
91
98
}
92
99
s .ClusterInCodefresh = installCmdOptions .clusterNameInCodefresh
93
100
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" ))
95
102
}
96
103
if installCmdOptions .installOnlyRuntimeEnvironment == true {
97
- registerRuntimeEnvironment ()
98
- return
104
+ builder .Add (plugins .RuntimeEnvironmentPluginType )
99
105
} else if installCmdOptions .skipRuntimeInstallation == true {
100
106
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" ))
102
108
}
103
109
s .RuntimeEnvironment = installCmdOptions .runtimeEnvironmentName
104
110
logrus .Info ("Skipping installation of runtime environment, installing venona only" )
105
- installvenona ( )
111
+ builder . Add ( plugins . VenonaPluginType )
106
112
} else {
107
- registerRuntimeEnvironment ()
108
- installvenona ()
113
+ builder .
114
+ Add (plugins .RuntimeEnvironmentPluginType ).
115
+ Add (plugins .VenonaPluginType )
109
116
}
110
117
if isUsingDefaultStorageClass (installCmdOptions .storageClass ) {
111
- configureVolumeProvisioner ( )
118
+ builder . Add ( plugins . VolumeProvisionerPluginType )
112
119
} else {
113
120
logrus .Info ("Non default StorageClass is set, skipping installation of volume provisioner" )
114
121
}
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
+ }
115
135
logrus .Info ("Installation completed Successfully\n " )
116
136
},
117
137
}
@@ -135,49 +155,3 @@ func init() {
135
155
installCmd .Flags ().BoolVar (& installCmdOptions .dryRun , "dry-run" , false , "Set to true to simulate installation" )
136
156
installCmd .Flags ().BoolVar (& installCmdOptions .setDefaultRuntime , "set-default" , false , "Mark the install runtime-environment as default one after installation" )
137
157
}
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