forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved new actions from extensions in the shepherd repo.
- Loading branch information
igomez06
committed
Aug 20, 2024
1 parent
c044f84
commit 1b85eb9
Showing
225 changed files
with
13,112 additions
and
385 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
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,269 @@ | ||
package charts | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/rancher/shepherd/pkg/api/steve/catalog/types" | ||
|
||
appv1 "k8s.io/api/apps/v1" | ||
|
||
"github.com/rancher/rancher/tests/v2/actions/workloads" | ||
"github.com/rancher/shepherd/clients/rancher" | ||
steveV1 "github.com/rancher/shepherd/clients/rancher/v1" | ||
"github.com/rancher/shepherd/extensions/charts" | ||
kwait "k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
const ( | ||
repoType = "catalog.cattle.io.clusterrepo" | ||
appsType = "catalog.cattle.io.apps" | ||
awsUpstreamCloudProviderRepo = "https://github.com/kubernetes/cloud-provider-aws.git" | ||
masterBranch = "master" | ||
AwsUpstreamChartName = "aws-cloud-controller-manager" | ||
kubeSystemNamespace = "kube-system" | ||
) | ||
|
||
// InstallAWSOutOfTreeChart installs the CSI chart for aws cloud provider in a given cluster. | ||
func InstallAWSOutOfTreeChart(client *rancher.Client, installOptions *InstallOptions, repoName, clusterID string, isLeaderMigration bool) 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 | ||
} | ||
|
||
awsChartInstallActionPayload := &payloadOpts{ | ||
InstallOptions: *installOptions, | ||
Name: AwsUpstreamChartName, | ||
Namespace: kubeSystemNamespace, | ||
Host: serverSetting.Value, | ||
DefaultRegistry: registrySetting.Value, | ||
} | ||
|
||
chartInstallAction := awsChartInstallAction(awsChartInstallActionPayload, repoName, kubeSystemNamespace, installOptions.ProjectID, isLeaderMigration) | ||
|
||
catalogClient, err := client.GetClusterCatalogClient(installOptions.Cluster.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = catalogClient.InstallChart(chartInstallAction, repoName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = charts.WaitChartInstall(catalogClient, kubeSystemNamespace, AwsUpstreamChartName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
steveclient, err := client.Steve.ProxyDownstream(clusterID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
chartNodeSelector := map[string]string{ | ||
"node-role.kubernetes.io/controlplane": "true", | ||
} | ||
err = updateHelmNodeSelectors(steveclient, kubeSystemNamespace, AwsUpstreamChartName, chartNodeSelector) | ||
|
||
return err | ||
} | ||
|
||
// awsChartInstallAction is a helper function that returns a chartInstallAction for aws out-of-tree chart. | ||
func awsChartInstallAction(awsChartInstallActionPayload *payloadOpts, repoName, chartNamespace, chartProject string, isLeaderMigration bool) *types.ChartInstallAction { | ||
chartValues := map[string]interface{}{ | ||
"args": []interface{}{ | ||
"--use-service-account-credentials=true", | ||
"--configure-cloud-routes=false", | ||
"--v=2", | ||
"--cloud-provider=aws", | ||
}, | ||
// note: order of []interface{} must match the chart's order. A union is taken in the order given (not a pure replacement of the object) | ||
"clusterRoleRules": []interface{}{ | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"events", | ||
}, | ||
"verbs": []interface{}{ | ||
"patch", | ||
"create", | ||
"update", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"nodes", | ||
}, | ||
"verbs": []interface{}{ | ||
"*", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"nodes/status", | ||
}, | ||
"verbs": []interface{}{ | ||
"patch", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"services", | ||
}, | ||
"verbs": []interface{}{ | ||
"list", | ||
"patch", | ||
"update", | ||
"watch", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"services/status", | ||
}, | ||
"verbs": []interface{}{ | ||
"list", | ||
"patch", | ||
"update", | ||
"watch", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"serviceaccounts", | ||
}, | ||
"verbs": []interface{}{ | ||
"get", | ||
"create", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"persistentvolumes", | ||
}, | ||
"verbs": []interface{}{ | ||
"get", | ||
"list", | ||
"update", | ||
"watch", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"endpoints", | ||
}, | ||
"verbs": []interface{}{ | ||
"get", | ||
"create", | ||
"list", | ||
"watch", | ||
"update", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{ | ||
"coordination.k8s.io", | ||
}, | ||
"resources": []interface{}{ | ||
"leases", | ||
}, | ||
"verbs": []interface{}{ | ||
"get", | ||
"create", | ||
"list", | ||
"watch", | ||
"update", | ||
}, | ||
}, | ||
map[string]interface{}{ | ||
"apiGroups": []interface{}{""}, | ||
"resources": []interface{}{ | ||
"serviceaccounts/token", | ||
}, | ||
"verbs": []interface{}{ | ||
"create", | ||
}, | ||
}, | ||
}, | ||
"nodeSelector": map[string]interface{}{ | ||
"node-role.kubernetes.io/controlplane": "true", | ||
}, | ||
"tolerations": []interface{}{ | ||
map[string]interface{}{ | ||
"effect": "NoSchedule", | ||
"value": "true", | ||
"key": "node-role.kubernetes.io/controlplane", | ||
}, | ||
map[string]interface{}{ | ||
"effect": "NoSchedule", | ||
"value": "true", | ||
"key": "node.cloudprovider.kubernetes.io/uninitialized", | ||
}, | ||
map[string]interface{}{ | ||
"effect": "NoSchedule", | ||
"value": "true", | ||
"key": "node-role.kubernetes.io/master", | ||
}, | ||
}, | ||
} | ||
if isLeaderMigration { | ||
chartValues["args"] = append(chartValues["args"].([]interface{}), "--enable-leader-migration=true") | ||
} | ||
|
||
chartInstall := newChartInstall( | ||
awsChartInstallActionPayload.Name, | ||
awsChartInstallActionPayload.Version, | ||
awsChartInstallActionPayload.Cluster.ID, | ||
awsChartInstallActionPayload.Cluster.Name, | ||
awsChartInstallActionPayload.Host, | ||
repoName, | ||
chartProject, | ||
awsChartInstallActionPayload.DefaultRegistry, | ||
chartValues) | ||
chartInstalls := []types.ChartInstall{*chartInstall} | ||
|
||
return newChartInstallAction(chartNamespace, awsChartInstallActionPayload.ProjectID, chartInstalls) | ||
} | ||
|
||
// updateHelmNodeSelectors is a function that updates the newNodeSelector for a given Daemonset's nodeSelector. This is required due to an | ||
// upstream bug in helm charts, where you can't override the nodeSelector during a deployment of an upstream chart. | ||
func updateHelmNodeSelectors(client *steveV1.Client, daemonsetNamespace, daemonsetName string, newNodeSelector map[string]string) error { | ||
err := kwait.Poll(1*time.Second, 1*time.Minute, func() (done bool, err error) { | ||
_, err = client.SteveType(workloads.DaemonsetSteveType).ByID(daemonsetNamespace + "/" + daemonsetName) | ||
if err != nil { | ||
return false, nil | ||
} | ||
return true, nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
steveDaemonset, err := client.SteveType(workloads.DaemonsetSteveType).ByID(daemonsetNamespace + "/" + daemonsetName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
daemonsetObject := new(appv1.DaemonSet) | ||
err = steveV1.ConvertToK8sType(steveDaemonset, &daemonsetObject) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
daemonsetObject.Spec.Template.Spec.NodeSelector = newNodeSelector | ||
|
||
_, err = client.SteveType(workloads.DaemonsetSteveType).Update(steveDaemonset, daemonsetObject) | ||
return err | ||
} |
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,69 @@ | ||
package charts | ||
|
||
import ( | ||
"github.com/rancher/shepherd/extensions/clusters" | ||
) | ||
|
||
const ( | ||
// defaultRegistrySettingID is a private constant string that contains the ID of system default registry setting. | ||
defaultRegistrySettingID = "system-default-registry" | ||
// serverURLSettingID is a private constant string that contains the ID of server URL setting. | ||
serverURLSettingID = "server-url" | ||
rancherChartsName = "rancher-charts" | ||
active = "active" | ||
) | ||
|
||
// InstallOptions is a struct of the required options to install a chart. | ||
type InstallOptions struct { | ||
Cluster *clusters.ClusterMeta | ||
Version string | ||
ProjectID string | ||
} | ||
|
||
// payloadOpts is a private struct that contains the options for the chart payloads. | ||
// It is used to avoid passing the same options to different functions while using the chart helpers. | ||
type payloadOpts struct { | ||
InstallOptions | ||
Name string | ||
Namespace string | ||
Host string | ||
DefaultRegistry string | ||
} | ||
|
||
// RancherIstioOpts is a struct of the required options to install Rancher Istio with desired chart values. | ||
type RancherIstioOpts struct { | ||
IngressGateways bool | ||
EgressGateways bool | ||
Pilot bool | ||
Telemetry bool | ||
Kiali bool | ||
Tracing bool | ||
CNI bool | ||
} | ||
|
||
// RancherMonitoringOpts is a struct of the required options to install Rancher Monitoring with desired chart values. | ||
type RancherMonitoringOpts struct { | ||
IngressNginx bool `json:"ingressNginx" yaml:"ingressNginx"` | ||
ControllerManager bool `json:"controllerManager" yaml:"controllerManager"` | ||
Etcd bool `json:"etcd" yaml:"etcd"` | ||
Proxy bool `json:"proxy" yaml:"proxy"` | ||
Scheduler bool `json:"scheduler" yaml:"scheduler"` | ||
} | ||
|
||
// RancherLoggingOpts is a struct of the required options to install Rancher Logging with desired chart values. | ||
type RancherLoggingOpts struct { | ||
AdditionalLoggingSources bool | ||
} | ||
|
||
// RancherAlertingOpts is a struct of the required options to install Rancher Alerting Drivers with desired chart values. | ||
type RancherAlertingOpts struct { | ||
SMS bool | ||
Teams bool | ||
} | ||
|
||
// GetChartCaseEndpointResult is a struct that GetChartCaseEndpoint helper function returns. | ||
// It contains the boolean for healthy response and the request body. | ||
type GetChartCaseEndpointResult struct { | ||
Ok bool | ||
Body string | ||
} |
Oops, something went wrong.