Skip to content

Commit

Permalink
Add charts url setting (rancher#43530)
Browse files Browse the repository at this point in the history
* Add default chart URL setting

This adds new settings to control the origin of system, partner and RKE2
charts, which can now be tested with custom versions prior to releasing
corresponding RCs to their respective repositories:
* `ChartDefaultURL` (`rancher/charts`)
* `PartnerChartDefaultURL` (`rancher/partner- charts`)
* `RKE2ChartDefaultURL` (`rancher/rke2- charts`)

These options are intended for internal use only. When in use, Rancher
issues a warning suggesting to unset them should any issues be
encountered when fetching charts.

* Group settings by repo type

This moves each default branch setting, for the partner and RKE2 charts
repositories, next to the default URL settings for the respective
repository, to make configuration easier and improve documentation.
  • Loading branch information
weyfonk committed Jun 6, 2024
1 parent c0f2d83 commit 77891a6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
44 changes: 38 additions & 6 deletions pkg/data/dashboard/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/rancher/rancher/pkg/features"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/rancher/rancher/pkg/settings"
Expand All @@ -14,23 +15,38 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const defaultURL = "https://git.rancher.io/"

var (
prefix = "rancher-"
)

func addRepo(wrangler *wrangler.Context, repoName, branchName string) error {
func addRepo(wrangler *wrangler.Context, repoName, repoURL, branchName string) error {
if repoURL == "" || repoURL == defaultURL {
repoURL = defaultURL + strings.TrimPrefix(repoName, prefix)
} else {
logrus.Warnf(
"Charts URL for %q set to %q, which is not the default (%q). "+
"If Rancher has issues finding charts, consider resetting this to the default value",
repoName,
repoURL,
defaultURL,
)
}

repo, err := wrangler.Catalog.ClusterRepo().Get(repoName, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
_, err = wrangler.Catalog.ClusterRepo().Create(&v1.ClusterRepo{
ObjectMeta: metav1.ObjectMeta{
Name: repoName,
},
Spec: v1.RepoSpec{
GitRepo: "https://git.rancher.io/" + strings.TrimPrefix(repoName, prefix),
GitRepo: repoURL,
GitBranch: branchName,
},
})
} else if err == nil && repo.Spec.GitBranch != branchName {
} else if err == nil && (repo.Spec.GitRepo != repoURL || repo.Spec.GitBranch != branchName) {
repo.Spec.GitRepo = repoURL
repo.Spec.GitBranch = branchName
_, err = wrangler.Catalog.ClusterRepo().Update(repo)
}
Expand All @@ -40,15 +56,31 @@ func addRepo(wrangler *wrangler.Context, repoName, branchName string) error {

// addRepos upserts the rancher-charts, rancher-partner-charts and rancher-rke2-charts ClusterRepos
func addRepos(ctx context.Context, wrangler *wrangler.Context) error {
if err := addRepo(wrangler, "rancher-charts", settings.ChartDefaultBranch.Get()); err != nil {
if err := addRepo(
wrangler,
"rancher-charts",
settings.ChartDefaultURL.Get(),
settings.ChartDefaultBranch.Get(),
); err != nil {
return err
}
if err := addRepo(wrangler, "rancher-partner-charts", settings.PartnerChartDefaultBranch.Get()); err != nil {

if err := addRepo(
wrangler,
"rancher-partner-charts",
settings.PartnerChartDefaultURL.Get(),
settings.PartnerChartDefaultBranch.Get(),
); err != nil {
return err
}

if features.RKE2.Enabled() {
if err := addRepo(wrangler, "rancher-rke2-charts", settings.RKE2ChartDefaultBranch.Get()); err != nil {
if err := addRepo(
wrangler,
"rancher-rke2-charts",
settings.RKE2ChartDefaultURL.Get(),
settings.RKE2ChartDefaultBranch.Get(),
); err != nil {
return err
}
}
Expand Down
20 changes: 18 additions & 2 deletions pkg/settings/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ var (
SystemCatalog = NewSetting("system-catalog", "external") // Options are 'external' or 'bundled'
ChartDefaultBranch = NewSetting("chart-default-branch", "dev-v2.8")
SystemManagedChartsOperationTimeout = NewSetting("system-managed-charts-operation-timeout", "300s")
PartnerChartDefaultBranch = NewSetting("partner-chart-default-branch", "main")
RKE2ChartDefaultBranch = NewSetting("rke2-chart-default-branch", "main")
FleetDefaultWorkspaceName = NewSetting("fleet-default-workspace-name", fleetconst.ClustersDefaultNamespace) // fleetWorkspaceName to assign to clusters with none
ShellImage = NewSetting("shell-image", buildconfig.DefaultShellVersion)
IgnoreNodeName = NewSetting("ignore-node-name", "") // nodes to ignore when syncing v1.node to v3.node
Expand Down Expand Up @@ -145,6 +143,10 @@ var (
// AuthUserSessionTTLMinutes represents the time to live for tokens used for login sessions in minutes.
AuthUserSessionTTLMinutes = NewSetting("auth-user-session-ttl-minutes", "960") // 16 hours

// ChartDefaultURL represents the default URL for the system charts repo. It should only be set for test or
// debug purposes.
ChartDefaultURL = NewSetting("chart-default-url", "https://git.rancher.io/")

// ConfigMapName name of the configmap that stores rancher configuration information.
// Deprecated: to be removed in 2.8.0
ConfigMapName = NewSetting("config-map-name", "rancher-config")
Expand All @@ -168,9 +170,23 @@ var (
// If set to false the kubeconfig will contain a command to login to Rancher.
KubeconfigGenerateToken = NewSetting("kubeconfig-generate-token", "true")

// PartnerChartDefaultBranch represents the default branch for the partner charts repo.
PartnerChartDefaultBranch = NewSetting("partner-chart-default-branch", "main")

// PartnerChartDefaultURL represents the default URL for the partner charts repo. It should only be set for test
// or debug purposes.
PartnerChartDefaultURL = NewSetting("partner-chart-default-url", "https://git.rancher.io/")

// RancherWebhookVersion is the exact version of the webhook that Rancher will install.
RancherWebhookVersion = NewSetting("rancher-webhook-version", "")

// RKE2ChartDefaultBranch represents the default branch for the RKE2 charts repo.
RKE2ChartDefaultBranch = NewSetting("rke2-chart-default-branch", "main")

// RKE2ChartDefaultURL represents the default URL for the RKE2 charts repo. It should only be set for test or
// debug purposes.
RKE2ChartDefaultURL = NewSetting("rke2-chart-default-url", "https://git.rancher.io/")

// SystemDefaultRegistry is the default contrainer registry used for images.
// The environmental variable "CATTLE_BASE_REGISTRY" controls the default value of this setting.
SystemDefaultRegistry = NewSetting("system-default-registry", os.Getenv("CATTLE_BASE_REGISTRY"))
Expand Down

0 comments on commit 77891a6

Please sign in to comment.