Skip to content

Commit b80b9cb

Browse files
Fix e2e tests
Signed-off-by: Rendre Greyling <rendre.greyling@nokia.com>
1 parent a086b7e commit b80b9cb

5 files changed

Lines changed: 63 additions & 50 deletions

File tree

deployments/porch/9-controllers.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ spec:
5151
imagePullPolicy: IfNotPresent
5252
args:
5353
- --repositories.cache-type=DB
54+
- --repositories.push-drafts-to-git=false
5455
- --repositories.create-v1alpha2-rpkg=false
5556
securityContext:
5657
runAsNonRoot: true

scripts/create-deployment-blueprint.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Supported Flags:
4242
--ghcr-image-prefix PREFIX ... GHCR image url prefix for running porch behind a proxy
4343
--fn-runner-warm-up-pod-cache BOOL ... disable warm-up-pod-cache in function runner
4444
--porch-cache-type TYPE ... porch cache type (CR or DB)
45-
--db-push-drafts-to-git BOOL ... enable db-push-drafts-to-git flag for porch-server
45+
--db-push-drafts-to-git BOOL ... enable draft push flags for porch-server and porch-controllers
4646
--create-v1alpha2-rpkg BOOL ... enable v1alpha2 PackageRevision CRD creation by repo controller
4747
EOF
4848
exit 1
@@ -246,6 +246,13 @@ function enable_db_push_drafts_to_git() {
246246
--match-name porch-server \
247247
--match-namespace porch-system \
248248
-- by-value="--db-push-drafts-to-git=false" put-value="--db-push-drafts-to-git=true"
249+
250+
kpt fn eval ${DESTINATION} \
251+
--image ${SEARCH_REPLACE_IMG} \
252+
--match-kind Deployment \
253+
--match-name porch-controllers \
254+
--match-namespace porch-system \
255+
-- by-value="--repositories.push-drafts-to-git=false" put-value="--repositories.push-drafts-to-git=true"
249256
}
250257

251258
function enable_v1alpha2_packagerevisions() {

test/e2e/api/db_git_sync_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
package api
1616

1717
import (
18+
"context"
1819
"time"
1920

2021
porchapi "github.com/kptdev/porch/api/porch/v1alpha1"
21-
configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1"
2222
suiteutils "github.com/kptdev/porch/test/e2e/suiteutils"
2323
"k8s.io/apimachinery/pkg/types"
24+
"k8s.io/apimachinery/pkg/util/wait"
2425
"sigs.k8s.io/controller-runtime/pkg/client"
2526
)
2627

@@ -29,29 +30,29 @@ const (
2930
dbGitSyncWaitTimeout = 60 * time.Second
3031
)
3132

32-
func (t *PorchSuite) updatePRR(repoName string, prr *porchapi.PackageRevisionResources, resourceKeys ...string) {
33+
func (t *PorchSuite) updatePRR(_ string, prr *porchapi.PackageRevisionResources, resourceKeys ...string) {
34+
t.T().Helper()
3335
t.UpdateF(prr)
34-
if t.UsingDBCache {
35-
return
36-
}
37-
var repo configapi.Repository
38-
t.GetF(client.ObjectKey{Namespace: t.Namespace, Name: repoName}, &repo)
39-
if repo.Annotations[configapi.AnnotationKeyV1Alpha2Migration] != configapi.AnnotationValueMigrationEnabled {
40-
return
41-
}
36+
4237
prName := prr.Name
43-
t.Require().Eventually(func() bool {
38+
err := wait.PollUntilContextTimeout(t.GetContext(), time.Second, dbGitSyncWaitTimeout, true, func(ctx context.Context) (bool, error) {
4439
var latest porchapi.PackageRevisionResources
45-
if err := t.Reader.Get(t.GetContext(), client.ObjectKey{Namespace: t.Namespace, Name: prName}, &latest); err != nil {
46-
return false
40+
if err := t.Reader.Get(ctx, client.ObjectKey{Namespace: t.Namespace, Name: prName}, &latest); err != nil {
41+
return false, nil
4742
}
4843
for _, key := range resourceKeys {
4944
if _, ok := latest.Spec.Resources[key]; !ok {
50-
return false
45+
return false, nil
5146
}
5247
}
53-
return t.CheckRenderError(&latest.Status.RenderStatus) == nil
54-
}, dbGitSyncWaitTimeout, time.Second)
48+
if err := t.CheckRenderError(&latest.Status.RenderStatus); err != nil {
49+
return false, nil
50+
}
51+
return true, nil
52+
})
53+
if err != nil {
54+
t.Fatalf("updatePRR: PRR %q did not reflect update (keys %v) within %v", prName, resourceKeys, dbGitSyncWaitTimeout)
55+
}
5556
}
5657

5758
func (t *PorchSuite) TestSyncDraftSurvivesSyncWhenInGit() {
@@ -469,7 +470,8 @@ data:
469470
// repo is still archived. This advances the external commit past
470471
// lastPushedCommitTimestamp, satisfying extChanged = true.
471472
t.SetGiteaRepoArchived(giteaRepo, false)
472-
t.GiteaCommitFileToBranch(giteaRepo, branchName, gitFileKey,
473+
gitFilePath := packageName + "/" + gitFileKey
474+
t.GiteaCommitFileToBranch(giteaRepo, branchName, gitFilePath,
473475
`apiVersion: v1
474476
kind: ConfigMap
475477
metadata:

test/e2e/suiteutils/gitea_test_utils.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ const (
4343
defaultGiteaLBIP = "172.18.255.200"
4444
)
4545

46-
// GetGiteaURL returns the appropriate Gitea URL based on whether Porch server is running in cluster
47-
func (t *TestSuite) GetGiteaURL() string {
48-
if t.IsPorchServerInCluster() {
49-
return t.GiteaUrl + "/" + t.GiteaUser + "/"
50-
}
51-
return "http://localhost:3000/porch/"
52-
}
53-
5446
func (t *TestSuite) GetGiteaApiURL() string {
5547
if t.GiteaUrl == GiteaClusterURL {
5648
return "http://localhost:3000"
@@ -180,7 +172,7 @@ func (t *TestSuite) CreateGiteaRepoNoCleanup(repoName string) string {
180172
}
181173
t.Logf("CreateGiteaRepoNoCleanup: created repo %q", repoName)
182174

183-
return t.GetGiteaURL() + repoName + ".git"
175+
return t.getGiteaURL() + repoName + ".git"
184176
}
185177

186178
// DeleteGiteaRepo deletes a Gitea repository owned by t.GiteaUser.

test/e2e/suiteutils/suite_utils.go

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -799,55 +799,66 @@ func (t *TestSuite) GetPackageRevisionWithFilter(repo, pkgName string, filter Pa
799799
return &prList.Items[0]
800800
}
801801

802-
// TriggerRepoSync schedules a one-time sync for the given repository by setting
803-
// spec.sync.runOnceAt to now+7s, then waits for the sync to complete.
804802
func (t *TestSuite) TriggerRepoSync(repoName string, timeout time.Duration) {
805803
t.T().Helper()
806804
repoKey := client.ObjectKey{Namespace: t.Namespace, Name: repoName}
807805

808806
var repo configapi.Repository
809807
t.GetF(repoKey, &repo)
810808

809+
baselineLastSync := time.Time{}
810+
if repo.Status.LastFullSyncTime != nil {
811+
baselineLastSync = repo.Status.LastFullSyncTime.Time
812+
}
813+
811814
if repo.Spec.Sync == nil {
812815
repo.Spec.Sync = &configapi.RepositorySync{}
813816
}
814-
// The handleRunOnceAt goroutine polls every 5s and requires time.Until(runOnceAt) > 0
815-
// when it observes the change, so we add 8s of lead time to be safe.
816-
repo.Spec.Sync.RunOnceAt = ptr.To(metav1.NewTime(time.Now().Add(8 * time.Second)))
817+
// Schedule runOnceAt slightly in the past so the controller's isOneTimeSyncDue
818+
// check triggers a full sync on the next reconcile without an extra delay.
819+
runOnceAt := metav1.NewTime(time.Now().Add(-1 * time.Second))
820+
repo.Spec.Sync.RunOnceAt = ptr.To(runOnceAt)
817821
t.UpdateF(&repo)
818822

819823
t.Logf("TriggerRepoSync: set runOnceAt for repo %s, waiting for sync to complete", repoName)
820-
t.WaitForNextRepoSync(repoName, timeout)
824+
t.WaitForNextRepoSync(repoName, timeout, baselineLastSync, runOnceAt.Time)
821825
}
822826

823-
// WaitForNextRepoSync waits until the Ready condition message changes, indicating a sync cycle completed.
824-
func (t *TestSuite) WaitForNextRepoSync(repoName string, timeout time.Duration) {
827+
func (t *TestSuite) WaitForNextRepoSync(repoName string, timeout time.Duration, baselineLastSync, triggeredRunOnceAt time.Time) {
825828
t.T().Helper()
826829
repoKey := client.ObjectKey{Namespace: t.Namespace, Name: repoName}
827830

828-
var repo configapi.Repository
829-
t.GetF(repoKey, &repo)
830-
831-
currentMsg := ""
832-
for _, cond := range repo.Status.Conditions {
833-
if cond.Type == configapi.RepositoryReady {
834-
currentMsg = cond.Message
835-
break
836-
}
837-
}
838-
839-
t.Logf("WaitForNextRepoSync: waiting for repo %s condition to change from %q (timeout %v)", repoName, currentMsg, timeout)
831+
t.Logf("WaitForNextRepoSync: waiting for repo %s full sync after LastFullSyncTime %v (timeout %v)",
832+
repoName, baselineLastSync, timeout)
840833
waitErr := wait.PollUntilContextTimeout(t.GetContext(), 1*time.Second, timeout, false, func(ctx context.Context) (bool, error) {
841834
var latest configapi.Repository
842835
if err := t.Reader.Get(ctx, repoKey, &latest); err != nil {
843836
return false, err
844837
}
838+
839+
ready := false
845840
for _, cond := range latest.Status.Conditions {
846-
if cond.Type == configapi.RepositoryReady && cond.Message != currentMsg {
847-
t.Logf("WaitForNextRepoSync: repo %s sync completed (new message=%q)", repoName, cond.Message)
848-
return true, nil
841+
if cond.Type == configapi.RepositoryReady && cond.Status == metav1.ConditionTrue {
842+
ready = true
843+
break
849844
}
850845
}
846+
if !ready {
847+
return false, nil
848+
}
849+
850+
if latest.Status.LastFullSyncTime != nil && latest.Status.LastFullSyncTime.Time.After(baselineLastSync) {
851+
t.Logf("WaitForNextRepoSync: repo %s sync completed (LastFullSyncTime=%s)",
852+
repoName, latest.Status.LastFullSyncTime.Time.Format(time.RFC3339))
853+
return true, nil
854+
}
855+
856+
if latest.Status.ObservedRunOnceAt != nil && latest.Status.ObservedRunOnceAt.Time.Equal(triggeredRunOnceAt) {
857+
t.Logf("WaitForNextRepoSync: repo %s runOnceAt sync completed (ObservedRunOnceAt=%s)",
858+
repoName, latest.Status.ObservedRunOnceAt.Time.Format(time.RFC3339))
859+
return true, nil
860+
}
861+
851862
return false, nil
852863
})
853864

0 commit comments

Comments
 (0)