diff --git a/pkg/data/dashboard/repo.go b/pkg/data/dashboard/repo.go index 8f40bd254dc..84e728e303d 100644 --- a/pkg/data/dashboard/repo.go +++ b/pkg/data/dashboard/repo.go @@ -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" @@ -14,11 +15,25 @@ 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{ @@ -26,11 +41,12 @@ func addRepo(wrangler *wrangler.Context, repoName, branchName string) error { 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) } @@ -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 } } diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index f73cb2de27f..635a9596a9c 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -116,8 +116,6 @@ var ( SystemCatalog = NewSetting("system-catalog", "external") // Options are 'external' or 'bundled' ChartDefaultBranch = NewSetting("chart-default-branch", "dev-v2.9") 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 @@ -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") @@ -177,9 +179,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"))