Skip to content

Commit

Permalink
feat(application): add SkipCrds to helm source (#169)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MrLuje authored Jul 3, 2022
1 parent 752dead commit 1917df8
Show file tree
Hide file tree
Showing 18 changed files with 895 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
argocd_version: ["v2.2.5", "v2.1.10"]
argocd_version: ["v2.3.0", "v2.2.5", "v2.1.10"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
Expand Down
2 changes: 2 additions & 0 deletions argocd/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
featureProjectScopedClusters
featureClusterMetadata
featureRepositoryCertificates
featureApplicationHelmSkipCrds
)

var (
Expand All @@ -38,6 +39,7 @@ var (
featureProjectScopedClusters: semver.MustParse("2.2.0"),
featureClusterMetadata: semver.MustParse("2.2.0"),
featureRepositoryCertificates: semver.MustParse("1.2.0"),
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
}
)

Expand Down
20 changes: 20 additions & 0 deletions argocd/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func testAccPreCheck(t *testing.T) {
}
}

// Skip test if feature is not supported
func testAccPreCheckFeatureSupported(t *testing.T, feature int) {
v := os.Getenv("ARGOCD_VERSION")
if v == "" {
Expand All @@ -60,3 +61,22 @@ func testAccPreCheckFeatureSupported(t *testing.T, feature int) {
t.Skipf("version %s does not support feature", v)
}
}

// Skip test if feature is supported
func testAccPreCheckFeatureNotSupported(t *testing.T, feature int) {
v := os.Getenv("ARGOCD_VERSION")
if v == "" {
t.Skip("ARGOCD_VERSION must be set set for feature supported acceptance tests")
}
serverVersion, err := semver.NewVersion(v)
if err != nil {
t.Fatalf("could not parse ARGOCD_VERSION as semantic version: %s", v)
}
versionConstraint, ok := featureVersionConstraintsMap[feature]
if !ok {
t.Fatal("feature constraint is not handled by the provider")
}
if i := versionConstraint.Compare(serverVersion); i != 1 {
t.Skipf("version %s does not support feature", v)
}
}
64 changes: 61 additions & 3 deletions argocd/resource_argocd_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package argocd
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

applicationClient "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
application "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/gitops-engine/pkg/health"
Expand All @@ -21,13 +22,12 @@ func resourceArgoCDApplication() *schema.Resource {
ReadContext: resourceArgoCDApplicationRead,
UpdateContext: resourceArgoCDApplicationUpdate,
DeleteContext: resourceArgoCDApplicationDelete,
// TODO: add importer acceptance tests
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"metadata": metadataSchema("applications.argoproj.io"),
"spec": applicationSpecSchema(),
"spec": applicationSpecSchemaV1(),
"wait": {
Type: schema.TypeBool,
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.",
Expand All @@ -41,6 +41,14 @@ func resourceArgoCDApplication() *schema.Resource {
Default: true,
},
},
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceArgoCDApplicationV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceArgoCDApplicationStateUpgradeV0,
Version: 0,
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Expand Down Expand Up @@ -140,6 +148,31 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
}
}

featureApplicationHelmSkipCrdsSupported, err := server.isFeatureSupported(featureApplicationHelmSkipCrds)
if err != nil {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: "feature not supported",
Detail: err.Error(),
},
}
}

if !featureApplicationHelmSkipCrdsSupported {
_, skipCrdsOk := d.GetOk("spec.0.source.0.helm.0.skip_crds")
if skipCrdsOk {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(
"application helm skip_crds is only supported from ArgoCD %s onwards",
featureVersionConstraintsMap[featureApplicationHelmSkipCrds].String()),
},
}
}
}

app, err = c.Create(ctx, &applicationClient.ApplicationCreateRequest{
Application: application.Application{

Expand Down Expand Up @@ -322,6 +355,31 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
}
}

featureApplicationHelmSkipCrdsSupported, err := server.isFeatureSupported(featureApplicationHelmSkipCrds)
if err != nil {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: "feature not supported",
Detail: err.Error(),
},
}
}

if !featureApplicationHelmSkipCrdsSupported {
_, skipCrdsOk := d.GetOk("spec.0.source.0.helm.0.skip_crds")
if skipCrdsOk {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(
"application helm skip_crds is only supported from ArgoCD %s onwards",
featureVersionConstraintsMap[featureApplicationHelmSkipCrds].String()),
},
}
}
}

app, err := c.Get(ctx, &applicationClient.ApplicationQuery{
Name: &appName,
})
Expand Down
Loading

0 comments on commit 1917df8

Please sign in to comment.