[api,platform] Decouple CozyRDs from API HR

This commit patches the Cozystack API server to tolerate an absence of
Cozystack Resource Definitions either registered as CRDs on the k8s API
or simply as an absence of CozyRDs persisted to etcd. This decouples the
upgrade of the CozyRD CRD from the upgrade of the Cozystack API.

```release-note
[api,platform] Decouple the Cozystack API from the Cozystack Resource
Definitions, allowing independent upgrades of either one and a more
reliable migration from 0.36 to 0.37.
```

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
This commit is contained in:
Timofei Larkin
2025-10-08 16:18:44 +03:00
parent a369171a20
commit 4e766ed82e
37 changed files with 753 additions and 5 deletions

View File

@@ -224,7 +224,7 @@ func buildPostProcessV3(kindSchemas map[string]string) func(*spec3.OpenAPI) (*sp
base, ok1 := doc.Components.Schemas[baseRef]
list, ok2 := doc.Components.Schemas[baseListRef]
stat, ok3 := doc.Components.Schemas[baseStatusRef]
if !(ok1 && ok2 && ok3) {
if !(ok1 && ok2 && ok3) && len(kindSchemas) > 0 {
return doc, fmt.Errorf("base Application* schemas not found")
}
@@ -339,7 +339,7 @@ func buildPostProcessV2(kindSchemas map[string]string) func(*spec.Swagger) (*spe
base, ok1 := defs[baseRef]
list, ok2 := defs[baseListRef]
stat, ok3 := defs[baseStatusRef]
if !(ok1 && ok2 && ok3) {
if !(ok1 && ok2 && ok3) && len(kindSchemas) > 0 {
return sw, fmt.Errorf("base Application* schemas not found")
}

View File

@@ -24,6 +24,7 @@ import (
"fmt"
"io"
"net"
"time"
v1alpha1 "github.com/cozystack/cozystack/api/v1alpha1"
appsv1alpha1 "github.com/cozystack/cozystack/pkg/apis/apps/v1alpha1"
@@ -161,8 +162,33 @@ func (o *CozyServerOptions) Complete() error {
crdList := &v1alpha1.CozystackResourceDefinitionList{}
if err := o.Client.List(context.Background(), crdList); err != nil {
return fmt.Errorf("failed to list CozystackResourceDefinitions: %w", err)
// Retry with exponential backoff for at least 30 minutes
const maxRetryDuration = 30 * time.Minute
const initialDelay = time.Second
const maxDelay = 2 * time.Minute
startTime := time.Now()
delay := initialDelay
for {
err := o.Client.List(context.Background(), crdList)
if err == nil {
break
}
// Check if we've exceeded the maximum retry duration
if time.Since(startTime) >= maxRetryDuration {
return fmt.Errorf("failed to list CozystackResourceDefinitions after %v: %w", maxRetryDuration, err)
}
// Log the error and wait before retrying
fmt.Printf("Failed to list CozystackResourceDefinitions (retrying in %v): %v\n", delay, err)
time.Sleep(delay)
delay = time.Duration(float64(delay) * 1.5)
if delay > maxDelay {
delay = maxDelay
}
}
// Convert to ResourceConfig