Skip to content

Commit 4f1427d

Browse files
authored
removed strategy from clone task (#371)
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
1 parent aaee5e6 commit 4f1427d

12 files changed

Lines changed: 4 additions & 117 deletions

File tree

api/generated/openapi/zz_generated.openapi.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/porch/types.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,6 @@ type PackageCloneTaskSpec struct {
199199

200200
// `Upstream` is the reference to the upstream package to clone.
201201
Upstream UpstreamPackage `json:"upstreamRef,omitempty"`
202-
203-
// Defines which strategy should be used to update the package. It defaults to 'resource-merge'.
204-
// * resource-merge: Perform a structural comparison of the original /
205-
// updated resources, and merge the changes into the local package.
206-
// * fast-forward: Fail without updating if the local package was modified
207-
// since it was fetched.
208-
// * force-delete-replace: Wipe all the local changes to the package and replace
209-
// it with the remote version.
210-
// * copy-merge: Copy all the remote changes to the local package.
211-
Strategy PackageMergeStrategy `json:"strategy,omitempty"`
212202
}
213203

214204
type PackageMergeStrategy string

api/porch/v1alpha1/types.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,6 @@ type PackageCloneTaskSpec struct {
200200

201201
// `Upstream` is the reference to the upstream package to clone.
202202
Upstream UpstreamPackage `json:"upstreamRef,omitempty"`
203-
204-
// Defines which strategy should be used to update the package. It defaults to 'resource-merge'.
205-
// * resource-merge: Perform a structural comparison of the original /
206-
// updated resources, and merge the changes into the local package.
207-
// * fast-forward: Fail without updating if the local package was modified
208-
// since it was fetched.
209-
// * force-delete-replace: Wipe all the local changes to the package and replace
210-
// it with the remote version.
211-
// * copy-merge: Copy all the remote changes to the local package.
212-
Strategy PackageMergeStrategy `json:"strategy,omitempty"`
213203
}
214204

215205
type PackageMergeStrategy string

api/porch/v1alpha1/zz_generated.conversion.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/commands/rpkg/clone/command.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ const (
3535
command = "cmdrpkgclone"
3636
)
3737

38-
var (
39-
strategies = []string{
40-
string(porchapi.ResourceMerge),
41-
string(porchapi.FastForward),
42-
string(porchapi.ForceDeleteReplace),
43-
string(porchapi.CopyMerge),
44-
}
45-
)
38+
4639

4740
func NewCommand(ctx context.Context, rcg *genericclioptions.ConfigFlags) *cobra.Command {
4841
return newRunner(ctx, rcg).Command
@@ -64,8 +57,6 @@ func newRunner(ctx context.Context, rcg *genericclioptions.ConfigFlags) *runner
6457
}
6558
r.Command = c
6659

67-
c.Flags().StringVar(&r.strategy, "strategy", string(porchapi.ResourceMerge),
68-
"update strategy that should be used when updating this package; one of: "+strings.Join(strategies, ","))
6960
c.Flags().StringVar(&r.directory, "directory", "", "Directory within the repository where the upstream package is located.")
7061
c.Flags().StringVar(&r.ref, "ref", "", "Branch in the repository where the upstream package is located.")
7162
c.Flags().StringVar(&r.repository, "repository", "", "Repository to which package will be cloned (downstream repository).")
@@ -84,7 +75,6 @@ type runner struct {
8475
clone porchapi.PackageCloneTaskSpec
8576

8677
// Flags
87-
strategy string
8878
directory string
8979
ref string
9080
repository string // Target repository
@@ -101,12 +91,6 @@ func (r *runner) preRunE(_ *cobra.Command, args []string) error {
10191
}
10292
r.client = client
10393

104-
mergeStrategy, err := toMergeStrategy(r.strategy)
105-
if err != nil {
106-
return errors.E(op, err)
107-
}
108-
r.clone.Strategy = mergeStrategy
109-
11094
if len(args) < 2 {
11195
return errors.E(op, fmt.Errorf("SOURCE_PACKAGE and NAME are required positional arguments; %d provided", len(args)))
11296
}
@@ -218,18 +202,3 @@ func (r *runner) runE(cmd *cobra.Command, _ []string) error {
218202
fmt.Fprintf(cmd.OutOrStdout(), "%s created\n", pr.Name)
219203
return nil
220204
}
221-
222-
func toMergeStrategy(strategy string) (porchapi.PackageMergeStrategy, error) {
223-
switch strategy {
224-
case string(porchapi.ResourceMerge):
225-
return porchapi.ResourceMerge, nil
226-
case string(porchapi.FastForward):
227-
return porchapi.FastForward, nil
228-
case string(porchapi.ForceDeleteReplace):
229-
return porchapi.ForceDeleteReplace, nil
230-
case string(porchapi.CopyMerge):
231-
return porchapi.CopyMerge, nil
232-
default:
233-
return "", fmt.Errorf("invalid strategy: %q", strategy)
234-
}
235-
}

pkg/cli/commands/rpkg/clone/command_test.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,32 +114,6 @@ func TestCmd(t *testing.T) {
114114
}
115115
}
116116

117-
func TestToMergeStrategy(t *testing.T) {
118-
tests := []struct {
119-
input string
120-
expected porchapi.PackageMergeStrategy
121-
hasError bool
122-
}{
123-
{input: string(porchapi.ResourceMerge), expected: porchapi.ResourceMerge, hasError: false},
124-
{input: string(porchapi.FastForward), expected: porchapi.FastForward, hasError: false},
125-
{input: string(porchapi.ForceDeleteReplace), expected: porchapi.ForceDeleteReplace, hasError: false},
126-
{input: string(porchapi.CopyMerge), expected: porchapi.CopyMerge, hasError: false},
127-
{input: "invalid-strategy", expected: "", hasError: true},
128-
}
129-
130-
for _, test := range tests {
131-
t.Run(test.input, func(t *testing.T) {
132-
result, err := toMergeStrategy(test.input)
133-
if test.hasError {
134-
assert.Error(t, err)
135-
} else {
136-
assert.NoError(t, err)
137-
assert.Equal(t, test.expected, result)
138-
}
139-
})
140-
}
141-
}
142-
143117
func TestPreRunE(t *testing.T) {
144118
tests := []struct {
145119
name string
@@ -150,7 +124,7 @@ func TestPreRunE(t *testing.T) {
150124
{
151125
name: "Missing arguments",
152126
args: []string{"source-package"},
153-
flags: map[string]string{"repository": "test-repo", "workspace": "test-workspace", "strategy": "copy-merge"},
127+
flags: map[string]string{"repository": "test-repo", "workspace": "test-workspace"},
154128
expectErr: true,
155129
},
156130
{
@@ -159,12 +133,6 @@ func TestPreRunE(t *testing.T) {
159133
flags: map[string]string{"repository": "", "workspace": ""},
160134
expectErr: true,
161135
},
162-
{
163-
name: "Invalid strategy",
164-
args: []string{"source-package", "target-package"},
165-
flags: map[string]string{"repository": "test-repo", "workspace": "test-workspace", "strategy": "invalid-strategy"},
166-
expectErr: true,
167-
},
168136
}
169137

170138
for _, test := range tests {
@@ -173,7 +141,6 @@ func TestPreRunE(t *testing.T) {
173141
r := &runner{
174142
ctx: context.Background(),
175143
cfg: &genericclioptions.ConfigFlags{},
176-
strategy: test.flags["strategy"],
177144
repository: test.flags["repository"],
178145
workspace: test.flags["workspace"],
179146
}

pkg/cli/commands/rpkg/docs/docs.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,15 @@ Flags:
7676
--workspace
7777
The workspace name assigned to the new downstream package revision. The default value is v1.
7878
79-
--strategy
80-
Update strategy that should be used when updating the new
81-
package revision. Must be one of:
82-
=resource-merge: (Default) Perform a structural comparison of the original
83-
updated resources, and merge the changes into the local package.
84-
=fast-forward: Fail without updating if the local package was modified since it was fetched.
85-
=force-delete-replace: Wipe all the local changes to the package and replace
86-
it with the remote version.
87-
=copy-merge: Copy all the remote changes to the local package.
88-
8979
--secret-ref
9080
Name of the secret containing basic authentication used to authenticate with the upstream repository (git-only).
9181
Naturally, this secret has to exist in the kubernetes cluster and must be in the namespace
9282
where the package revision is to be created.
9383
`
9484
var CloneExamples = `
9585
# clone the 'example-repo.example-package-name.example-workspace' package and create a new package revision called
96-
# 'example-package-name-2' in the 'example-repo-2' repository with a new workspace named 'example-workspace-2' and 'force-delete-replace' update strategy.
97-
$ porchctl rpkg clone example-repo.example-package-name.example-workspace example-package-name-2 --repository=example-repo-2 --workspace=example-workspace-2 --strategy=force-delete-replace
86+
# 'example-package-name-2' in the 'example-repo-2' repository with a new workspace named 'example-workspace-2'.
87+
$ porchctl rpkg clone example-repo.example-package-name.example-workspace example-package-name-2 --repository=example-repo-2 --workspace=example-workspace-2
9888
9989
# clone the git repository at 'https://github.com/repo/blueprint.git' at reference 'base/v0' and in directory base. The new
10090
# package revision will be created in repository 'blueprint' and namespace 'default'.

pkg/engine/engine_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ func TestCreateCloneTaskValidation(t *testing.T) {
470470
{
471471
Type: porchapi.TaskTypeClone,
472472
Clone: &porchapi.PackageCloneTaskSpec{
473-
Strategy: porchapi.ResourceMerge,
474473
Upstream: porchapi.UpstreamPackage{
475474
Type: porchapi.RepositoryTypeGit,
476475
Git: &porchapi.GitPackage{

pkg/registry/porch/packagerevision_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ func TestUpdateStrategy(t *testing.T) {
296296
Directory: "/path/to/package",
297297
},
298298
},
299-
Strategy: "copy-merge",
300299
},
301300
},
302301
},

pkg/task/generictaskhandler.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ type genericTaskHandler struct {
4242
repoOpener repository.RepositoryOpener
4343
credentialResolver repository.CredentialResolver
4444
referenceResolver repository.ReferenceResolver
45-
cloneStrategy porchapi.PackageMergeStrategy
4645
repoOperationRetryAttempts int
4746
}
4847

@@ -79,11 +78,6 @@ func (th *genericTaskHandler) ApplyTask(ctx context.Context, draft repository.Pa
7978
return pkgerrors.New("task list must contain exactly 1 task")
8079
}
8180

82-
if cloneTask := obj.Spec.Tasks[0].Clone; cloneTask != nil {
83-
klog.Infof("Clone strategy is %s", cloneTask.Strategy)
84-
th.cloneStrategy = cloneTask.Strategy
85-
}
86-
8781
mut, err := th.mapTaskToMutation(obj, &obj.Spec.Tasks[0], repositoryObj.Spec.Deployment, packageConfig)
8882
if err != nil {
8983
return err

0 commit comments

Comments
 (0)