Skip to content

Commit

Permalink
Moved new actions from extensions in the shepherd repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
igomez06 committed Aug 20, 2024
1 parent c044f84 commit 1b85eb9
Show file tree
Hide file tree
Showing 225 changed files with 13,112 additions and 385 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ replace (
require (
github.com/antihax/optional v1.0.0
github.com/rancher/rancher/pkg/apis v0.0.0-20240719121207-baeda6b89fe3
github.com/rancher/shepherd v0.0.0-20240802212035-bdce62c2bc80
github.com/rancher/shepherd v0.0.0-20240820200736-1dc64edfa0a7
go.qase.io/client v0.0.0-20231114201952-65195ec001fa
)

Expand Down Expand Up @@ -142,6 +142,7 @@ require (
github.com/rancher/rke v1.6.0
github.com/rancher/steve v0.0.0-20240805194353-1d42891f81f7
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20210727200656-10b094e30007
github.com/rancher/wrangler v1.1.2
github.com/rancher/wrangler/v3 v3.0.0
github.com/robfig/cron v1.2.0
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -241,7 +242,6 @@ require (
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/rancher/wrangler v1.1.2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1795,8 +1795,8 @@ github.com/rancher/rke v1.6.0 h1:fHdygmtPF1cWXuiYXfwgG4hKvt0n4l57SwCxquRJSfs=
github.com/rancher/rke v1.6.0/go.mod h1:5xRbf3L8PxqJRhABjYRfaBqbpVqAnqyH3maUNQEuwvk=
github.com/rancher/saml v0.4.14-rancher3 h1:2NN6cPqm9FJeiT25x8+gLHWGdulsEak33cHRkGaJ5v0=
github.com/rancher/saml v0.4.14-rancher3/go.mod h1:S4+611dxnKt8z/ulbvaJzcgSHsuhjVc1QHNTcr1R7Fw=
github.com/rancher/shepherd v0.0.0-20240802212035-bdce62c2bc80 h1:/dkxdx/BGZOp7jN0QMUFHrldDOSV3UfxxPdDCjGMZrQ=
github.com/rancher/shepherd v0.0.0-20240802212035-bdce62c2bc80/go.mod h1:7qf+6wlqrQ2Bver/WPCFrT6ZnC0V3KLllOmd1pr8Was=
github.com/rancher/shepherd v0.0.0-20240820200736-1dc64edfa0a7 h1:aBzUsOTvmJFczSzhb6mQxAYKB1eNGV0oDmN1UmQ5oiY=
github.com/rancher/shepherd v0.0.0-20240820200736-1dc64edfa0a7/go.mod h1:nVphr8v6qtXd0pth8wMCF9U5eKEPBIaD5+HQCH19uRw=
github.com/rancher/steve v0.0.0-20240805194353-1d42891f81f7 h1:XLR3/81oMPStfXMHnSKihocl3RZo16Ap/mtbAV+Yosg=
github.com/rancher/steve v0.0.0-20240805194353-1d42891f81f7/go.mod h1:Za4nSt0V6kIHRfUo6jTXKkv6ABMMCHINA8EzhzygCfk=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20210727200656-10b094e30007 h1:ru+mqGnxMmKeU0Q3XIDxkARvInDIqT1hH2amTcsjxI4=
Expand Down
269 changes: 269 additions & 0 deletions tests/v2/actions/charts/awsoutoftree.go
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
}
69 changes: 69 additions & 0 deletions tests/v2/actions/charts/charts.go
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
}
Loading

0 comments on commit 1b85eb9

Please sign in to comment.