-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable automated install of vsphere cpi/csi
- Loading branch information
1 parent
9b663d9
commit 16f0740
Showing
11 changed files
with
331 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package charts | ||
|
||
import ( | ||
"github.com/rancher/shepherd/extensions/projects" | ||
"github.com/rancher/shepherd/extensions/rke1/nodetemplates" | ||
"github.com/rancher/shepherd/pkg/api/steve/catalog/types" | ||
|
||
"github.com/rancher/shepherd/clients/rancher" | ||
"github.com/rancher/shepherd/clients/rancher/catalog" | ||
r1vsphere "github.com/rancher/shepherd/extensions/rke1/nodetemplates/vsphere" | ||
) | ||
|
||
const ( | ||
systemProject = "System" | ||
vsphereCPIchartName = "rancher-vsphere-cpi" | ||
vsphereCSIchartName = "rancher-vsphere-csi" | ||
|
||
vcenter = "vCenter" | ||
storageclass = "storageClass" | ||
|
||
datacenters = "datacenters" | ||
host = "host" | ||
password = "password" | ||
username = "username" | ||
port = "port" | ||
clusterid = "clusterId" | ||
datastoreurl = "datastoreURL" | ||
) | ||
|
||
// InstallVsphereOutOfTreeCharts installs the CPI and CSI chart for aws cloud provider in a given cluster. | ||
func InstallVsphereOutOfTreeCharts(client *rancher.Client, vsphereTemplate *nodetemplates.NodeTemplate, repoName, clusterID string) error { | ||
|
||
serverSetting, err := client.Management.Setting.ByID(serverURLSettingID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
registrySetting, err := client.Management.Setting.ByID(defaultRegistrySettingID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
project, err := projects.GetProjectByName(client, clusterID, systemProject) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
catalogClient, err := client.GetClusterCatalogClient(clusterID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
latestCPIVersion, err := catalogClient.GetLatestChartVersion(vsphereCPIchartName, catalog.RancherChartRepo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
installCPIOptions := &InstallOptions{ | ||
ClusterID: clusterID, | ||
Version: latestCPIVersion, | ||
ProjectID: project.ID, | ||
} | ||
|
||
chartInstallActionPayload := &payloadOpts{ | ||
InstallOptions: *installCPIOptions, | ||
Name: vsphereCPIchartName, | ||
Namespace: kubeSystemNamespace, | ||
Host: serverSetting.Value, | ||
DefaultRegistry: registrySetting.Value, | ||
} | ||
|
||
chartInstallAction, err := vsphereCPIChartInstallAction(catalogClient, | ||
chartInstallActionPayload, vsphereTemplate, installCPIOptions, repoName, kubeSystemNamespace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = catalogClient.InstallChart(chartInstallAction, repoName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = VerifyChartInstall(catalogClient, kubeSystemNamespace, vsphereCPIchartName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
latestCSIVersion, err := catalogClient.GetLatestChartVersion(vsphereCSIchartName, catalog.RancherChartRepo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
installCSIOptions := &InstallOptions{ | ||
ClusterID: clusterID, | ||
Version: latestCSIVersion, | ||
ProjectID: project.ID, | ||
} | ||
|
||
chartInstallActionPayload = &payloadOpts{ | ||
InstallOptions: *installCSIOptions, | ||
Name: vsphereCSIchartName, | ||
Namespace: kubeSystemNamespace, | ||
Host: serverSetting.Value, | ||
DefaultRegistry: registrySetting.Value, | ||
} | ||
|
||
chartInstallAction, err = vsphereCSIChartInstallAction(catalogClient, chartInstallActionPayload, | ||
vsphereTemplate, installCSIOptions, repoName, kubeSystemNamespace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = catalogClient.InstallChart(chartInstallAction, repoName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
// vsphereCPIChartInstallAction is a helper function that returns a chartInstallAction for aws out-of-tree chart. | ||
func vsphereCPIChartInstallAction(client *catalog.Client, chartInstallActionPayload *payloadOpts, vsphereTemplate *nodetemplates.NodeTemplate, installOptions *InstallOptions, repoName, chartNamespace string) (*types.ChartInstallAction, error) { | ||
chartValues, err := client.GetChartValues(repoName, vsphereCPIchartName, installOptions.Version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
chartValues[vcenter].(map[string]interface{})[datacenters] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.Datacenter | ||
chartValues[vcenter].(map[string]interface{})[host] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.Vcenter | ||
chartValues[vcenter].(map[string]interface{})[password] = r1vsphere.GetVspherePassword() | ||
chartValues[vcenter].(map[string]interface{})[username] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.Username | ||
chartValues[vcenter].(map[string]interface{})[port] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.VcenterPort | ||
|
||
chartInstall := newChartInstall( | ||
chartInstallActionPayload.Name, | ||
chartInstallActionPayload.InstallOptions.Version, | ||
chartInstallActionPayload.InstallOptions.ClusterID, | ||
chartInstallActionPayload.InstallOptions.ClusterName, | ||
chartInstallActionPayload.Host, | ||
repoName, | ||
installOptions.ProjectID, | ||
chartInstallActionPayload.DefaultRegistry, | ||
chartValues) | ||
chartInstalls := []types.ChartInstall{*chartInstall} | ||
|
||
return newChartInstallAction(chartNamespace, chartInstallActionPayload.ProjectID, chartInstalls), nil | ||
} | ||
|
||
// vsphereCSIChartInstallAction is a helper function that returns a chartInstallAction for aws out-of-tree chart. | ||
func vsphereCSIChartInstallAction(client *catalog.Client, chartInstallActionPayload *payloadOpts, vsphereTemplate *nodetemplates.NodeTemplate, installOptions *InstallOptions, repoName, chartNamespace string) (*types.ChartInstallAction, error) { | ||
chartValues, err := client.GetChartValues(repoName, vsphereCSIchartName, installOptions.Version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
chartValues[vcenter].(map[string]interface{})[datacenters] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.Datacenter | ||
chartValues[vcenter].(map[string]interface{})[host] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.Vcenter | ||
chartValues[vcenter].(map[string]interface{})[password] = r1vsphere.GetVspherePassword() | ||
chartValues[vcenter].(map[string]interface{})[username] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.Username | ||
chartValues[vcenter].(map[string]interface{})[port] = vsphereTemplate.VmwareVsphereNodeTemplateConfig.VcenterPort | ||
chartValues[vcenter].(map[string]interface{})[clusterid] = installOptions.ClusterID | ||
|
||
chartValues[storageclass].(map[string]interface{})[datastoreurl] = r1vsphere.GetVsphereDatastoreUrl() | ||
|
||
chartInstall := newChartInstall( | ||
chartInstallActionPayload.Name, | ||
chartInstallActionPayload.InstallOptions.Version, | ||
chartInstallActionPayload.InstallOptions.ClusterID, | ||
chartInstallActionPayload.InstallOptions.ClusterName, | ||
chartInstallActionPayload.Host, | ||
repoName, | ||
installOptions.ProjectID, | ||
chartInstallActionPayload.DefaultRegistry, | ||
chartValues) | ||
chartInstalls := []types.ChartInstall{*chartInstall} | ||
|
||
return newChartInstallAction(chartNamespace, chartInstallActionPayload.ProjectID, chartInstalls), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.