mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
123 lines
5.2 KiB
Go
123 lines
5.2 KiB
Go
package e2e
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
. "github.com/hanzoai/cd/gitops-engine/pkg/sync/common"
|
|
|
|
applicationpkg "github.com/hanzoai/cd/pkg/apiclient/application"
|
|
. "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
. "github.com/hanzoai/cd/test/e2e/fixture"
|
|
. "github.com/hanzoai/cd/test/e2e/fixture/app"
|
|
"github.com/hanzoai/cd/util/errors"
|
|
utilio "github.com/hanzoai/cd/util/io"
|
|
)
|
|
|
|
const wardleAPIServiceName = "v1alpha1.wardle.example.com"
|
|
|
|
// TestAPIServiceLateRegistrationIsDiscovered verifies that when an aggregated
|
|
// (extension) API server is registered AFTER Argo CD is already running, the
|
|
// destination cluster cache picks up the newly served group/kind WITHOUT a manual
|
|
// cache invalidation or hard refresh.
|
|
//
|
|
// The scenario reproduces the original bug: starting Argo CD without the
|
|
// aggregated apiserver running means its group/kind is absent from discovery, so
|
|
// the cluster cache never watches it. Argo CD watches APIService objects and, on
|
|
// the fix, reacts to an APIService becoming Available by re-running discovery and
|
|
// starting the missing watches - mirroring the existing CRD handling.
|
|
//
|
|
// The assertion deliberately checks the application RESOURCE TREE (which is built
|
|
// purely from resources the cluster cache is watching) rather than the resource
|
|
// sync status. The sync status is not a reliable signal here because
|
|
// GetManagedLiveObjs falls back to a direct live API GET for kinds that are not
|
|
// watched, so a resource can show as Synced even though the cache never observed
|
|
// it - which is exactly why it would be missing from the UI/tree.
|
|
func TestAPIServiceLateRegistrationIsDiscovered(t *testing.T) {
|
|
// The aggregated apiserver infrastructure is cluster-scoped (Namespace,
|
|
// APIService, ClusterRole(Binding)s) and is not managed by an Argo CD app. It
|
|
// is labeled with e2e.apps.hanzo.ai=true so fixture.EnsureCleanState tears it
|
|
// down between tests; a dangling APIService backed by a deleted service would
|
|
// otherwise degrade discovery for subsequent tests.
|
|
const serverManifests = "testdata/aggregated-apiserver-server/manifests.yaml"
|
|
|
|
flunderManifest := `apiVersion: wardle.example.com/v1alpha1
|
|
kind: Flunder
|
|
metadata:
|
|
name: e2e-flunder
|
|
`
|
|
|
|
ctx := Given(t)
|
|
ctx.
|
|
Path("aggregated-apiserver").
|
|
When().
|
|
CreateApp().
|
|
Sync().
|
|
Then().
|
|
// Baseline: the app - and therefore the destination cluster cache - is
|
|
// synced and running before the aggregated API exists.
|
|
Expect(OperationPhaseIs(OperationSucceeded)).
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
Expect(ResourceSyncStatusIs("ConfigMap", "aggregated-apiserver-canary", SyncStatusCodeSynced)).
|
|
When().
|
|
And(func() {
|
|
// Register the extension apiserver AFTER Argo CD is up and wait until it
|
|
// is actually serving its API group.
|
|
errors.NewHandler(t).FailOnErr(Run("", "kubectl", "apply", "-f", serverManifests))
|
|
errors.NewHandler(t).FailOnErr(Run("", "kubectl", "-n", "wardle", "rollout", "status", "deployment/wardle-server", "--timeout=180s"))
|
|
errors.NewHandler(t).FailOnErr(Run("", "kubectl", "wait", "--for=condition=Available", "apiservice/"+wardleAPIServiceName, "--timeout=180s"))
|
|
}).
|
|
// Deliberately NO InvalidateCache and NO RefreshTypeHard here - the cache must
|
|
// discover the new kind on its own in response to the APIService event.
|
|
AddFile("flunder.yaml", flunderManifest).
|
|
Refresh(RefreshTypeNormal).
|
|
Sync().
|
|
Then().
|
|
Expect(OperationPhaseIs(OperationSucceeded)).
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
And(func(app *Application) {
|
|
// The Flunder appears in the resource tree only if the cluster cache
|
|
// discovered the aggregated kind and is watching it. This is the behavior
|
|
// under test: without reacting to the APIService event, the cache never
|
|
// watches wardle.example.com and the Flunder is absent from the tree (and
|
|
// the UI) until a manual invalidation.
|
|
closer, cdClient := ArgoCDClientset.NewApplicationClientOrDie()
|
|
defer utilio.Close(closer)
|
|
|
|
require.Eventually(t, func() bool {
|
|
// Trigger a normal (soft) refresh so the controller recomputes the
|
|
// resource tree from the live cluster cache. This does NOT invalidate
|
|
// the cache or re-run discovery: without the APIService fix the kind
|
|
// remains unwatched, so the Flunder never enters the tree regardless of
|
|
// how many times we refresh.
|
|
refresh := string(RefreshTypeNormal)
|
|
if _, err := cdClient.Get(context.Background(), &applicationpkg.ApplicationQuery{
|
|
Name: &app.Name,
|
|
AppNamespace: &app.Namespace,
|
|
Project: []string{app.Spec.Project},
|
|
Refresh: &refresh,
|
|
}); err != nil {
|
|
t.Logf("app refresh failed: %v", err)
|
|
}
|
|
tree, err := cdClient.ResourceTree(context.Background(), &applicationpkg.ResourcesQuery{
|
|
ApplicationName: &app.Name,
|
|
AppNamespace: &app.Namespace,
|
|
Project: &app.Spec.Project,
|
|
})
|
|
if err != nil {
|
|
t.Logf("failed to get resource tree: %v", err)
|
|
return false
|
|
}
|
|
for _, node := range tree.Nodes {
|
|
if node.Group == "wardle.example.com" && node.Kind == "Flunder" && node.Name == "e2e-flunder" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}, 90*time.Second, 3*time.Second, "Flunder should appear in the application resource tree without a cache invalidation")
|
|
})
|
|
}
|