From 99c9ede2202e75c7fde6dce2eec22ea79d53db77 Mon Sep 17 00:00:00 2001 From: Diogo Souza Date: Fri, 1 Nov 2024 19:13:53 -0300 Subject: [PATCH] checking for OCIDownloaded condition --- rancher2/resource_rancher2_catalog_v2.go | 15 ++++++++++++--- rancher2/resource_rancher2_catalog_v2_test.go | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/rancher2/resource_rancher2_catalog_v2.go b/rancher2/resource_rancher2_catalog_v2.go index 87c33397..944f8d66 100644 --- a/rancher2/resource_rancher2_catalog_v2.go +++ b/rancher2/resource_rancher2_catalog_v2.go @@ -48,7 +48,7 @@ func resourceRancher2CatalogV2Create(d *schema.ResourceData, meta interface{}) e d.SetId(clusterID + catalogV2ClusterIDsep + newCatalog.ID) stateConf := &resource.StateChangeConf{ Pending: []string{}, - Target: []string{"downloaded"}, + Target: []string{"downloaded", "ociDownloaded"}, Refresh: catalogV2StateRefreshFunc(meta, clusterID, newCatalog.ID), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 1 * time.Second, @@ -103,7 +103,7 @@ func resourceRancher2CatalogV2Update(d *schema.ResourceData, meta interface{}) e d.SetId(clusterID + catalogV2ClusterIDsep + newCatalog.ID) stateConf := &resource.StateChangeConf{ Pending: []string{}, - Target: []string{"downloaded"}, + Target: []string{"downloaded", "ociDownloaded"}, Refresh: catalogV2StateRefreshFunc(meta, clusterID, newCatalog.ID), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 1 * time.Second, @@ -169,6 +169,15 @@ func catalogV2StateRefreshFunc(meta interface{}, clusterID, catalogID string) re } return nil, "error", fmt.Errorf("%s", obj.Status.Conditions[i].Message) } + if obj.Status.Conditions[i].Type == string(v1.OCIDownloaded) { + if obj.Status.Conditions[i].Status == "Unknown" { + return obj, "transitioning", nil + } + if obj.Status.Conditions[i].Status == "True" { + return obj, "ociDownloaded", nil + } + return nil, "error", fmt.Errorf("%s", obj.Status.Conditions[i].Message) + } } return obj, "transitioning", nil } @@ -317,7 +326,7 @@ func waitCatalogV2Downloaded(c *Config, clusterID, catalogID string) (*ClusterRe return nil, fmt.Errorf("Getting catalog V2 ID (%s): %v", catalogID, err) } for i := range obj.Status.Conditions { - if obj.Status.Conditions[i].Type == string(v1.RepoDownloaded) { + if obj.Status.Conditions[i].Type == string(v1.RepoDownloaded) || obj.Status.Conditions[i].Type == string(v1.OCIDownloaded) { // Status of the condition, one of True, False, Unknown. if obj.Status.Conditions[i].Status == "Unknown" { break diff --git a/rancher2/resource_rancher2_catalog_v2_test.go b/rancher2/resource_rancher2_catalog_v2_test.go index 160637dd..156321f7 100644 --- a/rancher2/resource_rancher2_catalog_v2_test.go +++ b/rancher2/resource_rancher2_catalog_v2_test.go @@ -13,8 +13,10 @@ const testAccRancher2CatalogV2Type = "rancher2_catalog_v2" var ( testAccRancher2CatalogV2 string + testAccRancher2OCICatalogV2 string testAccRancher2CatalogV2Update string testAccRancher2CatalogV2Config string + testAccRancher2OCICatalogV2Config string testAccRancher2CatalogV2UpdateConfig string ) @@ -35,7 +37,16 @@ resource "` + testAccRancher2CatalogV2Type + `" "foo" { git_branch = "master" } ` + testAccRancher2OCICatalogV2 = ` +resource "` + testAccRancher2CatalogV2Type + `" "foo" { + cluster_id = rancher2_cluster_sync.testacc.cluster_id + name = "foo" + url = "oci://chartproxy.container-registry.com/docs.projectcalico.org/charts" + git_branch = "dev-v2.5" +} +` testAccRancher2CatalogV2Config = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2CatalogV2 + testAccRancher2OCICatalogV2Config = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2OCICatalogV2 testAccRancher2CatalogV2UpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2CatalogV2Update } @@ -47,6 +58,14 @@ func TestAccRancher2CatalogV2_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckRancher2CatalogV2Destroy, Steps: []resource.TestStep{ + { + Config: testAccRancher2OCICatalogV2Config, + Check: resource.ComposeTestCheckFunc( + testAccCheckRancher2CatalogV2Exists(testAccRancher2CatalogV2Type+".foo", catalog), + resource.TestCheckResourceAttr(testAccRancher2CatalogV2Type+".foo", "name", "foo"), + resource.TestCheckResourceAttr(testAccRancher2CatalogV2Type+".foo", "url", "oci://chartproxy.container-registry.com/docs.projectcalico.org/charts"), + ), + }, { Config: testAccRancher2CatalogV2Config, Check: resource.ComposeTestCheckFunc(