mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
fix: revert kubeVersion change to preserve trailing + (#24066)
Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
This commit is contained in:
committed by
GitHub
parent
45a7a18256
commit
f78cddf736
@@ -1,19 +1,5 @@
|
||||
# v3.0 to 3.1
|
||||
|
||||
## No more KubeVersions variable modification
|
||||
|
||||
Until v3.0, Argo CD removed `+` identifier from `kubeVersions` in Helm, Kustomize and Plugins. For example, if Argo CD receive `kubeVersions` as vX.Y.Z+, we convert to vX.Y.Z internally. Starting with v3.1, the internal conversion is entirely removed.
|
||||
|
||||
### Detection
|
||||
|
||||
To detect if you are affected, check the `kubeVersions` you are using. If you use `kubeVersions` including `+` identifier, the application must be failed when you upgrade from v3.0 to v3.1.
|
||||
|
||||
### Remediation
|
||||
|
||||
The plus symbol was originally removed [because Helm did not support it](https://github.com/argoproj/argo-cd/issues/2303). Helm no longer enforces this restriction, so apps should work fine even if your kubeVersions include `+`.
|
||||
|
||||
However, since Argo CD now sends unmodified kubeVersions to Helm, the generated manifests may differ due to the changed kubeVersions. For apps which require extra caution, it may be advisable to disable auto-sync, upgrade, check any diffs, and then reenable auto-sync.
|
||||
|
||||
## Symlink protection in API `--staticassets` directory
|
||||
|
||||
The `--staticassets` directory in the API server (`/app/shared` by default) is now protected against out-of-bounds
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[Custom tools](../operator-manual/config-management-plugins.md), [Helm](helm.md), [Jsonnet](jsonnet.md), and [Kustomize](kustomize.md) support the following build env vars:
|
||||
|
||||
| Variable | Description |
|
||||
|-------------------------------------|-------------------------------------------------------------------------|
|
||||
| ----------------------------------- | ----------------------------------------------------------------------- |
|
||||
| `ARGOCD_APP_NAME` | The name of the application. |
|
||||
| `ARGOCD_APP_NAMESPACE` | The destination namespace of the application. |
|
||||
| `ARGOCD_APP_PROJECT_NAME` | The name of the project the application belongs to. |
|
||||
@@ -13,7 +13,7 @@
|
||||
| `ARGOCD_APP_SOURCE_PATH` | The path of the app within the source repo. |
|
||||
| `ARGOCD_APP_SOURCE_REPO_URL` | The source repo URL. |
|
||||
| `ARGOCD_APP_SOURCE_TARGET_REVISION` | The target revision from the spec, e.g. `master`. |
|
||||
| `KUBE_VERSION` | The version of Kubernetes. |
|
||||
| `KUBE_VERSION` | The semantic version of Kubernetes without trailing metadata. |
|
||||
| `KUBE_API_VERSIONS` | The version of the Kubernetes API. |
|
||||
|
||||
In case you don't want a variable to be interpolated, `$` can be escaped via `$$`.
|
||||
|
||||
@@ -40,6 +40,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
k8sversion "k8s.io/apimachinery/pkg/util/version"
|
||||
kubeyaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
|
||||
pluginclient "github.com/argoproj/argo-cd/v3/cmpserver/apiclient"
|
||||
@@ -1168,6 +1169,20 @@ func isSourcePermitted(url string, repos []string) bool {
|
||||
return p.IsSourcePermitted(v1alpha1.ApplicationSource{RepoURL: url})
|
||||
}
|
||||
|
||||
// parseKubeVersion is an helper function to remove the non-semantic information supported by kubernetes
|
||||
// that may not be supported in all helm versions: https://github.com/helm/helm/pull/31091
|
||||
func parseKubeVersion(version string) (string, error) {
|
||||
if version == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
kubeVersion, err := k8sversion.ParseGeneric(version)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return kubeVersion.String(), nil
|
||||
}
|
||||
|
||||
func helmTemplate(appPath string, repoRoot string, env *v1alpha1.Env, q *apiclient.ManifestRequest, isLocal bool, gitRepoPaths utilio.TempPaths) ([]*unstructured.Unstructured, string, error) {
|
||||
// We use the app name as Helm's release name property, which must not
|
||||
// contain any underscore characters and must not exceed 53 characters.
|
||||
@@ -1175,10 +1190,15 @@ func helmTemplate(appPath string, repoRoot string, env *v1alpha1.Env, q *apiclie
|
||||
// templating, thus, we just use the name part of the identifier.
|
||||
appName, _ := argo.ParseInstanceName(q.AppName, "")
|
||||
|
||||
kubeVersion, err := parseKubeVersion(q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion))
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("could not parse kubernetes version %s: %w", q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion), err)
|
||||
}
|
||||
|
||||
templateOpts := &helm.TemplateOpts{
|
||||
Name: appName,
|
||||
Namespace: q.ApplicationSource.GetNamespaceOrDefault(q.Namespace),
|
||||
KubeVersion: q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion),
|
||||
KubeVersion: kubeVersion,
|
||||
APIVersions: q.ApplicationSource.GetAPIVersionsOrDefault(q.ApiVersions),
|
||||
Set: map[string]string{},
|
||||
SetString: map[string]string{},
|
||||
@@ -1504,9 +1524,14 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting kustomize binary path: %w", err)
|
||||
}
|
||||
var kubeVersion string
|
||||
kubeVersion, err = parseKubeVersion(q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse kubernetes version %s: %w", q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion), err)
|
||||
}
|
||||
k := kustomize.NewKustomizeApp(repoRoot, appPath, q.Repo.GetGitCreds(gitCredsStore), repoURL, kustomizeBinary, q.Repo.Proxy, q.Repo.NoProxy)
|
||||
targetObjs, _, commands, err = k.Build(q.ApplicationSource.Kustomize, q.KustomizeOptions, env, &kustomize.BuildOpts{
|
||||
KubeVersion: q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion),
|
||||
KubeVersion: kubeVersion,
|
||||
APIVersions: q.ApplicationSource.GetAPIVersionsOrDefault(q.ApiVersions),
|
||||
})
|
||||
case v1alpha1.ApplicationSourceTypePlugin:
|
||||
@@ -2026,8 +2051,12 @@ func makeJsonnetVM(appPath string, repoRoot string, sourceJsonnet v1alpha1.Appli
|
||||
}
|
||||
|
||||
func getPluginEnvs(env *v1alpha1.Env, q *apiclient.ManifestRequest) ([]string, error) {
|
||||
kubeVersion, err := parseKubeVersion(q.KubeVersion)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse kubernetes version %s: %w", q.KubeVersion, err)
|
||||
}
|
||||
envVars := env.Environ()
|
||||
envVars = append(envVars, "KUBE_VERSION="+q.KubeVersion)
|
||||
envVars = append(envVars, "KUBE_VERSION="+kubeVersion)
|
||||
envVars = append(envVars, "KUBE_API_VERSIONS="+strings.Join(q.ApiVersions, ","))
|
||||
|
||||
return getPluginParamEnvs(envVars, q.ApplicationSource.Plugin)
|
||||
|
||||
@@ -1134,6 +1134,27 @@ func TestManifestGenErrorCacheRespectsNoCache(t *testing.T) {
|
||||
assert.True(t, strings.HasPrefix(err.Error(), cachedManifestGenerationPrefix))
|
||||
}
|
||||
|
||||
func TestGenerateHelmKubeVersion(t *testing.T) {
|
||||
service := newService(t, "../../util/helm/testdata/redis")
|
||||
|
||||
res, err := service.GenerateManifest(t.Context(), &apiclient.ManifestRequest{
|
||||
Repo: &v1alpha1.Repository{},
|
||||
AppName: "test",
|
||||
ApplicationSource: &v1alpha1.ApplicationSource{
|
||||
Path: ".",
|
||||
Helm: &v1alpha1.ApplicationSourceHelm{
|
||||
KubeVersion: "1.30.11+IKS",
|
||||
},
|
||||
},
|
||||
ProjectName: "something",
|
||||
ProjectSourceRepos: []string{"*"},
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.Commands, 1)
|
||||
assert.Contains(t, res.Commands[0], "--kube-version 1.30.11")
|
||||
}
|
||||
|
||||
func TestGenerateHelmWithValues(t *testing.T) {
|
||||
service := newService(t, "../../util/helm/testdata/redis")
|
||||
|
||||
@@ -4333,7 +4354,7 @@ func Test_GenerateManifests_Commands(t *testing.T) {
|
||||
q := apiclient.ManifestRequest{
|
||||
AppName: "test-app",
|
||||
Namespace: "test-namespace",
|
||||
KubeVersion: "1.2.3",
|
||||
KubeVersion: "1.2.3+something",
|
||||
ApiVersions: []string{"v1/Test", "v2/Test"},
|
||||
Repo: &v1alpha1.Repository{},
|
||||
ApplicationSource: &v1alpha1.ApplicationSource{
|
||||
@@ -4379,7 +4400,7 @@ func Test_GenerateManifests_Commands(t *testing.T) {
|
||||
t.Run("with overrides", func(t *testing.T) {
|
||||
// These can be set explicitly instead of using inferred values. Make sure the overrides apply.
|
||||
q.ApplicationSource.Helm.APIVersions = []string{"v3", "v4"}
|
||||
q.ApplicationSource.Helm.KubeVersion = "5.6.7"
|
||||
q.ApplicationSource.Helm.KubeVersion = "5.6.7+something"
|
||||
q.ApplicationSource.Helm.Namespace = "different-namespace"
|
||||
q.ApplicationSource.Helm.ReleaseName = "different-release-name"
|
||||
|
||||
@@ -4454,9 +4475,12 @@ images:
|
||||
q := apiclient.ManifestRequest{
|
||||
AppName: "test-app",
|
||||
Namespace: "test-namespace",
|
||||
KubeVersion: "1.2.3",
|
||||
KubeVersion: "1.2.3+something",
|
||||
ApiVersions: []string{"v1/Test", "v2/Test"},
|
||||
Repo: &v1alpha1.Repository{},
|
||||
KustomizeOptions: &v1alpha1.KustomizeOptions{
|
||||
BuildOptions: "--enable-helm",
|
||||
},
|
||||
ApplicationSource: &v1alpha1.ApplicationSource{
|
||||
Path: ".",
|
||||
Kustomize: &v1alpha1.ApplicationSourceKustomize{
|
||||
@@ -4475,7 +4499,7 @@ images:
|
||||
Images: v1alpha1.KustomizeImages{
|
||||
"image=override",
|
||||
},
|
||||
KubeVersion: "5.6.7",
|
||||
KubeVersion: "5.6.7+something",
|
||||
LabelWithoutSelector: true,
|
||||
LabelIncludeTemplates: true,
|
||||
NamePrefix: "test-prefix",
|
||||
@@ -4494,7 +4518,6 @@ images:
|
||||
}
|
||||
|
||||
res, err := service.GenerateManifest(t.Context(), &q)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{
|
||||
"kustomize edit set nameprefix -- test-prefix",
|
||||
@@ -4505,7 +4528,7 @@ images:
|
||||
"kustomize edit add annotation --force test:annotation-test-app",
|
||||
"kustomize edit set namespace -- override-namespace",
|
||||
"kustomize edit add component component",
|
||||
"kustomize build .",
|
||||
"kustomize build . --enable-helm --helm-kube-version 5.6.7 --helm-api-versions v1 --helm-api-versions v2",
|
||||
}, res.Commands)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user