Skip to content

Commit 1917df8

Browse files
authored
feat(application): add SkipCrds to helm source (#169)
* feat(application): add SkipCrds to helm source * feat: add StateUpgrader for skip_crds default value * test: add importer tests * add check featureApplicationHelmSkipCrds + v2.3.0 in test matrix * doc: add application helm skip_crds * test: missing 2.3.0 test condition * fix old redis image * add comment + rename test * fix(test): increase "go test" timeout from 5m to 8m
1 parent 752dead commit 1917df8

18 files changed

+895
-10
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
argocd_version: ["v2.2.5", "v2.1.10"]
17+
argocd_version: ["v2.3.0", "v2.2.5", "v2.1.10"]
1818
steps:
1919
- uses: actions/checkout@v2
2020
- uses: actions/setup-go@v1

argocd/features.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
featureProjectScopedClusters
2828
featureClusterMetadata
2929
featureRepositoryCertificates
30+
featureApplicationHelmSkipCrds
3031
)
3132

3233
var (
@@ -38,6 +39,7 @@ var (
3839
featureProjectScopedClusters: semver.MustParse("2.2.0"),
3940
featureClusterMetadata: semver.MustParse("2.2.0"),
4041
featureRepositoryCertificates: semver.MustParse("1.2.0"),
42+
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
4143
}
4244
)
4345

argocd/provider_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func testAccPreCheck(t *testing.T) {
4343
}
4444
}
4545

46+
// Skip test if feature is not supported
4647
func testAccPreCheckFeatureSupported(t *testing.T, feature int) {
4748
v := os.Getenv("ARGOCD_VERSION")
4849
if v == "" {
@@ -60,3 +61,22 @@ func testAccPreCheckFeatureSupported(t *testing.T, feature int) {
6061
t.Skipf("version %s does not support feature", v)
6162
}
6263
}
64+
65+
// Skip test if feature is supported
66+
func testAccPreCheckFeatureNotSupported(t *testing.T, feature int) {
67+
v := os.Getenv("ARGOCD_VERSION")
68+
if v == "" {
69+
t.Skip("ARGOCD_VERSION must be set set for feature supported acceptance tests")
70+
}
71+
serverVersion, err := semver.NewVersion(v)
72+
if err != nil {
73+
t.Fatalf("could not parse ARGOCD_VERSION as semantic version: %s", v)
74+
}
75+
versionConstraint, ok := featureVersionConstraintsMap[feature]
76+
if !ok {
77+
t.Fatal("feature constraint is not handled by the provider")
78+
}
79+
if i := versionConstraint.Compare(serverVersion); i != 1 {
80+
t.Skipf("version %s does not support feature", v)
81+
}
82+
}

argocd/resource_argocd_application.go

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package argocd
33
import (
44
"context"
55
"fmt"
6-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
76
"strings"
87
"time"
98

9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
1011
applicationClient "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
1112
application "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
1213
"github.com/argoproj/gitops-engine/pkg/health"
@@ -21,13 +22,12 @@ func resourceArgoCDApplication() *schema.Resource {
2122
ReadContext: resourceArgoCDApplicationRead,
2223
UpdateContext: resourceArgoCDApplicationUpdate,
2324
DeleteContext: resourceArgoCDApplicationDelete,
24-
// TODO: add importer acceptance tests
2525
Importer: &schema.ResourceImporter{
2626
StateContext: schema.ImportStatePassthroughContext,
2727
},
2828
Schema: map[string]*schema.Schema{
2929
"metadata": metadataSchema("applications.argoproj.io"),
30-
"spec": applicationSpecSchema(),
30+
"spec": applicationSpecSchemaV1(),
3131
"wait": {
3232
Type: schema.TypeBool,
3333
Description: "Upon application creation or update, wait for application health/sync status to be healthy/Synced, upon application deletion, wait for application to be removed, when set to true.",
@@ -41,6 +41,14 @@ func resourceArgoCDApplication() *schema.Resource {
4141
Default: true,
4242
},
4343
},
44+
SchemaVersion: 1,
45+
StateUpgraders: []schema.StateUpgrader{
46+
{
47+
Type: resourceArgoCDApplicationV0().CoreConfigSchema().ImpliedType(),
48+
Upgrade: resourceArgoCDApplicationStateUpgradeV0,
49+
Version: 0,
50+
},
51+
},
4452
Timeouts: &schema.ResourceTimeout{
4553
Create: schema.DefaultTimeout(5 * time.Minute),
4654
Update: schema.DefaultTimeout(5 * time.Minute),
@@ -140,6 +148,31 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
140148
}
141149
}
142150

151+
featureApplicationHelmSkipCrdsSupported, err := server.isFeatureSupported(featureApplicationHelmSkipCrds)
152+
if err != nil {
153+
return []diag.Diagnostic{
154+
{
155+
Severity: diag.Error,
156+
Summary: "feature not supported",
157+
Detail: err.Error(),
158+
},
159+
}
160+
}
161+
162+
if !featureApplicationHelmSkipCrdsSupported {
163+
_, skipCrdsOk := d.GetOk("spec.0.source.0.helm.0.skip_crds")
164+
if skipCrdsOk {
165+
return []diag.Diagnostic{
166+
{
167+
Severity: diag.Error,
168+
Summary: fmt.Sprintf(
169+
"application helm skip_crds is only supported from ArgoCD %s onwards",
170+
featureVersionConstraintsMap[featureApplicationHelmSkipCrds].String()),
171+
},
172+
}
173+
}
174+
}
175+
143176
app, err = c.Create(ctx, &applicationClient.ApplicationCreateRequest{
144177
Application: application.Application{
145178

@@ -322,6 +355,31 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
322355
}
323356
}
324357

358+
featureApplicationHelmSkipCrdsSupported, err := server.isFeatureSupported(featureApplicationHelmSkipCrds)
359+
if err != nil {
360+
return []diag.Diagnostic{
361+
{
362+
Severity: diag.Error,
363+
Summary: "feature not supported",
364+
Detail: err.Error(),
365+
},
366+
}
367+
}
368+
369+
if !featureApplicationHelmSkipCrdsSupported {
370+
_, skipCrdsOk := d.GetOk("spec.0.source.0.helm.0.skip_crds")
371+
if skipCrdsOk {
372+
return []diag.Diagnostic{
373+
{
374+
Severity: diag.Error,
375+
Summary: fmt.Sprintf(
376+
"application helm skip_crds is only supported from ArgoCD %s onwards",
377+
featureVersionConstraintsMap[featureApplicationHelmSkipCrds].String()),
378+
},
379+
}
380+
}
381+
}
382+
325383
app, err := c.Get(ctx, &applicationClient.ApplicationQuery{
326384
Name: &appName,
327385
})

0 commit comments

Comments
 (0)