Skip to content

Commit

Permalink
Fix some tests due to code changes between the initial PR and now
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Oct 5, 2022
1 parent 2357bd6 commit 1577969
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 72 deletions.
5 changes: 4 additions & 1 deletion cmd/entrypoint/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func (rw *realWaiter) Wait(ctx context.Context, file string, expectContent bool,
for {
select {
case <-ctx.Done():
return ctx.Err()
if ctx.Err() == context.DeadlineExceeded {
return ctx.Err()
}
return nil
case <-time.After(rw.waitPollingInterval):
}

Expand Down
25 changes: 0 additions & 25 deletions pkg/apis/config/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ const (
DefaultSendCloudEventsForRuns = false
// DefaultEmbeddedStatus is the default value for "embedded-status".
DefaultEmbeddedStatus = FullEmbeddedStatus
// DefaultEnableGitResolver is the default value for "enable-git-resolver".
DefaultEnableGitResolver = false
// DefaultEnableHubResolver is the default value for "enable-hub-resolver".
DefaultEnableHubResolver = false
// DefaultEnableBundlesResolver is the default value for "enable-bundles-resolver".
DefaultEnableBundlesResolver = false
// DefaultEnableCancelUsingEntrypoint is the default value for "enable-cancel-using-entrypoint"
DefaultEnableCancelUsingEntrypoint = false

Expand All @@ -82,13 +76,6 @@ const (
sendCloudEventsForRuns = "send-cloudevents-for-runs"
embeddedStatus = "embedded-status"

// EnableGitResolver is the flag used to enable the git remote resolver
EnableGitResolver = "enable-git-resolver"
// EnableHubResolver is the flag used to enable the hub remote resolver
EnableHubResolver = "enable-hub-resolver"
// EnableBundlesResolver is the flag used to enable the bundle remote resolver
EnableBundlesResolver = "enable-bundles-resolver"

// EnableCancelUsingEntrypoint is the flag used to enable cancelling a pod using the entrypoint
EnableCancelUsingEntrypoint = "enable-cancel-using-entrypoint"
)
Expand All @@ -107,9 +94,6 @@ type FeatureFlags struct {
SendCloudEventsForRuns bool
AwaitSidecarReadiness bool
EmbeddedStatus string
EnableGitResolver bool
EnableHubResolver bool
EnableBundleResolver bool
EnableCancelUsingEntrypoint bool
}

Expand Down Expand Up @@ -162,15 +146,6 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
if err := setEmbeddedStatus(cfgMap, DefaultEmbeddedStatus, &tc.EmbeddedStatus); err != nil {
return nil, err
}
if err := setFeature(EnableGitResolver, DefaultEnableGitResolver, &tc.EnableGitResolver); err != nil {
return nil, err
}
if err := setFeature(EnableHubResolver, DefaultEnableHubResolver, &tc.EnableHubResolver); err != nil {
return nil, err
}
if err := setFeature(EnableBundlesResolver, DefaultEnableBundlesResolver, &tc.EnableBundleResolver); err != nil {
return nil, err
}
if err := setFeature(EnableCancelUsingEntrypoint, DefaultEnableCancelUsingEntrypoint, &tc.EnableCancelUsingEntrypoint); err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/config/feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) {
EnableAPIFields: "alpha",
SendCloudEventsForRuns: true,
EmbeddedStatus: "both",
EnableBundleResolver: true,
EnableCancelUsingEntrypoint: true,
},
fileName: "feature-flags-all-flags-set",
Expand Down
28 changes: 8 additions & 20 deletions pkg/pod/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,13 @@ func orderContainers(commonExtraEntrypointArgs []string, steps []corev1.Containe
for i, s := range steps {
var argsForEntrypoint = []string{}
idx := strconv.Itoa(i)
switch i {
case 0:
argsForEntrypoint = []string{
// First step waits for the Downward volume file.
"-wait_file", filepath.Join(downwardMountPoint, downwardMountReadyFile),
"-wait_file_content", // Wait for file contents, not just an empty file.
// Start next step.
"-post_file", filepath.Join(runDir, idx, "out"),
"-termination_path", terminationPath,
"-step_metadata_dir", filepath.Join(runDir, idx, "status"),
"-cancel_file", filepath.Join(downwardMountPoint, downwardMountCancelFile),
}
default:
// All other steps wait for previous file, write next file.
argsForEntrypoint = []string{
"-wait_file", filepath.Join(runDir, strconv.Itoa(i-1), "out"),
"-post_file", filepath.Join(runDir, idx, "out"),
"-termination_path", terminationPath,
"-step_metadata_dir", filepath.Join(runDir, idx, "status"),
"-cancel_file", filepath.Join(downwardMountPoint, downwardMountCancelFile),
if i == 0 {
if waitForReadyAnnotation {
argsForEntrypoint = append(argsForEntrypoint,
// First step waits for the Downward volume file.
"-wait_file", filepath.Join(downwardMountPoint, downwardMountReadyFile),
"-wait_file_content", // Wait for file contents, not just an empty file.
)
}
} else { // Not the first step - wait for previous
argsForEntrypoint = append(argsForEntrypoint, "-wait_file", filepath.Join(runDir, strconv.Itoa(i-1), "out"))
Expand All @@ -156,6 +143,7 @@ func orderContainers(commonExtraEntrypointArgs []string, steps []corev1.Containe
"-post_file", filepath.Join(runDir, idx, "out"),
"-termination_path", terminationPath,
"-step_metadata_dir", filepath.Join(runDir, idx, "status"),
"-cancel_file", filepath.Join(downwardMountPoint, downwardMountCancelFile),
)
argsForEntrypoint = append(argsForEntrypoint, commonExtraEntrypointArgs...)
if taskSpec != nil {
Expand Down
19 changes: 10 additions & 9 deletions pkg/pod/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestOrderContainersWithNoWait(t *testing.T) {
"-post_file", "/tekton/run/0/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/0/status",
"-cancel_file", "/tekton/downward/cancel",
"-entrypoint", "cmd", "--",
"arg1", "arg2",
},
Expand All @@ -138,6 +139,7 @@ func TestOrderContainersWithNoWait(t *testing.T) {
"-post_file", "/tekton/run/1/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/1/status",
"-cancel_file", "/tekton/downward/cancel",
"-entrypoint", "cmd1", "--",
"cmd2", "cmd3",
"arg1", "arg2",
Expand Down Expand Up @@ -390,6 +392,7 @@ func TestEntryPointOnError(t *testing.T) {
"-post_file", "/tekton/run/0/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/0/status",
"-cancel_file", "/tekton/downward/cancel",
"-on_error", "continue",
"-entrypoint", "cmd", "--",
},
Expand All @@ -404,6 +407,7 @@ func TestEntryPointOnError(t *testing.T) {
"-post_file", "/tekton/run/1/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/1/status",
"-cancel_file", "/tekton/downward/cancel",
"-on_error", "stopAndFail",
"-entrypoint", "cmd", "--",
},
Expand Down Expand Up @@ -482,10 +486,9 @@ func TestEntryPointStepOutputConfigs(t *testing.T) {
"-post_file", "/tekton/run/0/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/0/status",
"-cancel_file", "/tekton/downward/cancel",
"-stdout_path", "step-1-out",
"-cancel_file",
"/tekton/downward/cancel",
"-on_error", "continue",
// "-on_error", "continue",
"-entrypoint", "cmd", "--",
"arg1", "arg2",
},
Expand All @@ -499,10 +502,9 @@ func TestEntryPointStepOutputConfigs(t *testing.T) {
"-post_file", "/tekton/run/1/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/1/status",
"-cancel_file", "/tekton/downward/cancel",
"-stderr_path", "step-2-err",
"-cancel_file",
"/tekton/downward/cancel",
"-on_error", "stopAndFail",
// "-on_error", "stopAndFail",
"-entrypoint", "cmd1", "--",
"cmd2", "cmd3",
"arg1", "arg2",
Expand All @@ -517,11 +519,10 @@ func TestEntryPointStepOutputConfigs(t *testing.T) {
"-post_file", "/tekton/run/2/out",
"-termination_path", "/tekton/termination",
"-step_metadata_dir", "/tekton/run/2/status",
"-cancel_file", "/tekton/downward/cancel",
"-stdout_path", "step-3-out",
"-stderr_path", "step-3-err",
"-cancel_file",
"/tekton/downward/cancel",
"-on_error", "stopAndFail",
// "-on_error", "stopAndFail",
"-entrypoint", "cmd", "--",
"arg1", "arg2",
},
Expand Down
1 change: 1 addition & 0 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,7 @@ _EOF_
"/tekton/termination",
"-step_metadata_dir",
"/tekton/run/0/status",
"-cancel_file", "/tekton/downward/cancel",
"-entrypoint",
"cmd",
"--",
Expand Down
26 changes: 12 additions & 14 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ import (
clock "k8s.io/utils/clock/testing"
"knative.dev/pkg/apis"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
"knative.dev/pkg/changeset"
cminformer "knative.dev/pkg/configmap/informer"
"knative.dev/pkg/controller"
"knative.dev/pkg/kmeta"
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"

pkgreconciler "knative.dev/pkg/reconciler"
"knative.dev/pkg/system"

Expand Down Expand Up @@ -4601,7 +4599,7 @@ func TestReconcileOnCancelledTaskRunWithFeatureFlag(t *testing.T) {
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: "TaskRunCancelled",
Message: `TaskRun "test-taskrun-run-cancelled" was cancelled`,
Message: `TaskRun "test-taskrun-run-cancelled" was cancelled. `,
}

testCases := []struct {
Expand Down Expand Up @@ -4655,7 +4653,7 @@ func TestReconcileOnCancelledTaskRunWithFeatureFlag(t *testing.T) {

wantEvents := []string{
"Normal Started",
"Warning Failed TaskRun \"test-taskrun-run-cancelled\" was cancelled",
"Warning Failed TaskRun \"test-taskrun-run-cancelled\" was cancelled. ",
}
err = eventstest.CheckEventsOrdered(t, testAssets.Recorder.Events, "test-reconcile-on-cancelled-taskrun", wantEvents)
if !(err == nil) {
Expand Down Expand Up @@ -4794,12 +4792,12 @@ func TestCancelTaskRun(t *testing.T) {
},
}},
reason: v1beta1.TaskRunReasonCancelled,
message: "TaskRun test-taskrun-run-cancel was cancelled",
message: "TaskRun test-taskrun-run-cancel was cancelled. ",
expectedStatus: apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.TaskRunReasonCancelled.String(),
Message: "TaskRun test-taskrun-run-cancel was cancelled",
Message: "TaskRun test-taskrun-run-cancel was cancelled. ",
},
expectedStepStates: []v1beta1.StepState{
{
Expand Down Expand Up @@ -4859,12 +4857,12 @@ func TestCancelTaskRun(t *testing.T) {
},
}},
reason: v1beta1.TaskRunReasonCancelled,
message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled",
message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled. ",
expectedStatus: apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.TaskRunReasonCancelled.String(),
Message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled",
Message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled. ",
},
expectedStepStates: []v1beta1.StepState{
{
Expand Down Expand Up @@ -4940,12 +4938,12 @@ func TestCancelTaskRun(t *testing.T) {
},
}},
reason: v1beta1.TaskRunReasonCancelled,
message: "TaskRun test-taskrun-run-cancel-multiple-steps-waiting was cancelled",
message: "TaskRun test-taskrun-run-cancel-multiple-steps-waiting was cancelled. ",
expectedStatus: apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.TaskRunReasonCancelled.String(),
Message: "TaskRun test-taskrun-run-cancel-multiple-steps-waiting was cancelled",
Message: "TaskRun test-taskrun-run-cancel-multiple-steps-waiting was cancelled. ",
},
expectedStepStates: []v1beta1.StepState{
{
Expand Down Expand Up @@ -5016,12 +5014,12 @@ func TestCancelTaskRun(t *testing.T) {
},
}},
reason: v1beta1.TaskRunReasonCancelled,
message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled",
message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled. ",
expectedStatus: apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Reason: v1beta1.TaskRunReasonCancelled.String(),
Message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled",
Message: "TaskRun test-taskrun-run-cancel-multiple-steps was cancelled. ",
},
expectedStepStates: []v1beta1.StepState{
{
Expand Down Expand Up @@ -5149,6 +5147,8 @@ func podArgs(cmd string, stdoutPath string, stderrPath string, additionalArgs []
"/tekton/termination",
"-step_metadata_dir",
fmt.Sprintf("/tekton/run/%d/status", idx),
"-cancel_file",
"/tekton/downward/cancel",
)
if stdoutPath != "" {
args = append(args, "-stdout_path", stdoutPath)
Expand All @@ -5157,8 +5157,6 @@ func podArgs(cmd string, stdoutPath string, stderrPath string, additionalArgs []
args = append(args, "-stderr_path", stderrPath)
}
args = append(args,
"-cancel_file",
"/tekton/downward/cancel",
"-entrypoint",
cmd,
"--",
Expand Down
3 changes: 1 addition & 2 deletions test/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import (
"sync"
"testing"

"github.com/tektoncd/pipeline/test/parse"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/parse"
jsonpatch "gomodules.xyz/jsonpatch/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down

0 comments on commit 1577969

Please sign in to comment.