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]>
143 lines
3.4 KiB
Go
143 lines
3.4 KiB
Go
package applicationsets
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/test/e2e/fixture"
|
|
"github.com/hanzoai/cd/test/e2e/fixture/applicationsets/utils"
|
|
"github.com/hanzoai/cd/util/errors"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/dynamic"
|
|
)
|
|
|
|
// this implements the "then" part of given/when/then
|
|
type Consequences struct {
|
|
context *Context
|
|
actions *Actions
|
|
}
|
|
|
|
func (c *Consequences) Expect(e Expectation) *Consequences {
|
|
return c.ExpectWithDuration(e, time.Duration(30)*time.Second)
|
|
}
|
|
|
|
func (c *Consequences) ExpectWithDuration(e Expectation, timeout time.Duration) *Consequences {
|
|
// this invocation makes sure this func is not reported as the cause of the failure - we are a "test helper"
|
|
c.context.T().Helper()
|
|
var message string
|
|
var state state
|
|
sleepIntervals := []time.Duration{
|
|
10 * time.Millisecond,
|
|
20 * time.Millisecond,
|
|
50 * time.Millisecond,
|
|
100 * time.Millisecond,
|
|
200 * time.Millisecond,
|
|
300 * time.Millisecond,
|
|
500 * time.Millisecond,
|
|
1 * time.Second,
|
|
}
|
|
sleepIntervalsIdx := -1
|
|
for start := time.Now(); time.Since(start) < timeout; time.Sleep(sleepIntervals[sleepIntervalsIdx]) {
|
|
if sleepIntervalsIdx < len(sleepIntervals)-1 {
|
|
sleepIntervalsIdx++
|
|
}
|
|
state, message = e(c)
|
|
switch state {
|
|
case succeeded:
|
|
log.Infof("expectation succeeded: %s", message)
|
|
return c
|
|
case failed:
|
|
c.context.T().Fatalf("failed expectation: %s", message)
|
|
return c
|
|
}
|
|
log.Infof("expectation pending: %s", message)
|
|
}
|
|
c.context.T().Fatal("timeout waiting for: " + message)
|
|
return c
|
|
}
|
|
|
|
func (c *Consequences) And(block func()) *Consequences {
|
|
c.context.T().Helper()
|
|
block()
|
|
return c
|
|
}
|
|
|
|
func (c *Consequences) Given() *Context {
|
|
return c.context
|
|
}
|
|
|
|
func (c *Consequences) When() *Actions {
|
|
time.Sleep(fixture.WhenThenSleepInterval)
|
|
return c.actions
|
|
}
|
|
|
|
func (c *Consequences) app(name string) *v1alpha1.Application {
|
|
apps := c.apps()
|
|
|
|
for index, app := range apps {
|
|
if app.Name == name {
|
|
return &apps[index]
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Consequences) apps() []v1alpha1.Application {
|
|
c.context.T().Helper()
|
|
var namespace string
|
|
if c.context.switchToNamespace != "" {
|
|
namespace = string(c.context.switchToNamespace)
|
|
} else {
|
|
namespace = fixture.TestNamespace()
|
|
}
|
|
|
|
fixtureClient := utils.GetE2EFixtureK8sClient(c.context.T())
|
|
list, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(namespace).List(context.Background(), metav1.ListOptions{})
|
|
errors.CheckError(err)
|
|
|
|
if list == nil {
|
|
list = &v1alpha1.ApplicationList{}
|
|
}
|
|
|
|
return list.Items
|
|
}
|
|
|
|
func (c *Consequences) applicationSet(applicationSetName string) *v1alpha1.ApplicationSet {
|
|
c.context.T().Helper()
|
|
fixtureClient := utils.GetE2EFixtureK8sClient(c.context.T())
|
|
|
|
var appSetClientSet dynamic.ResourceInterface
|
|
|
|
if c.context.switchToNamespace != "" {
|
|
appSetClientSet = fixtureClient.ExternalAppSetClientsets[c.context.switchToNamespace]
|
|
} else {
|
|
appSetClientSet = fixtureClient.AppSetClientset
|
|
}
|
|
|
|
list, err := appSetClientSet.Get(context.Background(), applicationSetName, metav1.GetOptions{})
|
|
errors.CheckError(err)
|
|
|
|
var appSet v1alpha1.ApplicationSet
|
|
|
|
bytes, err := list.MarshalJSON()
|
|
if err != nil {
|
|
return &v1alpha1.ApplicationSet{}
|
|
}
|
|
|
|
err = json.Unmarshal(bytes, &appSet)
|
|
if err != nil {
|
|
return &v1alpha1.ApplicationSet{}
|
|
}
|
|
|
|
if appSet.Name == applicationSetName {
|
|
return &appSet
|
|
}
|
|
|
|
return &v1alpha1.ApplicationSet{}
|
|
}
|