Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking for OCIDownloaded condition #1436

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions rancher2/resource_rancher2_catalog_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions rancher2/resource_rancher2_catalog_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const testAccRancher2CatalogV2Type = "rancher2_catalog_v2"

var (
testAccRancher2CatalogV2 string
testAccRancher2OCICatalogV2 string
testAccRancher2CatalogV2Update string
testAccRancher2CatalogV2Config string
testAccRancher2OCICatalogV2Config string
testAccRancher2CatalogV2UpdateConfig string
)

Expand All @@ -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
}

Expand All @@ -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(
Expand Down