Unverified Commit 7d4d6691 authored by bryanl's avatar bryanl
Browse files

Don't change cluster in apply dry run modified



Add conditionals for object tagging and upserting.
Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
parent 3b4de9a6
......@@ -176,7 +176,12 @@ func (a *Apply) handleObject(obj *unstructured.Unstructured) (string, error) {
// preprocessObject preprocesses an object for it is applied to the cluster.
func (a *Apply) preprocessObject(obj *unstructured.Unstructured) error {
dm := newDefaultManaged()
return errors.Wrap(dm.Tag(obj), "tagging ksonnet managed object")
if !a.DryRun {
return errors.Wrap(dm.Tag(obj), "tagging ksonnet managed object")
}
log.Info("tagging ksonnet managed object", a.dryRunText())
return nil
}
// patchFromCluster patches an object with values that may exist in the cluster.
......@@ -185,6 +190,11 @@ func (a *Apply) patchFromCluster(obj *unstructured.Unstructured) (*unstructured.
}
func (a *Apply) upsert(obj *unstructured.Unstructured) (string, error) {
if a.DryRun {
log.Info("upserting object", a.dryRunText())
return "12345", nil
}
u := a.upserterFactory()
for i := applyConflictRetryCount; i > 0; i-- {
......
......@@ -82,6 +82,43 @@ func Test_Apply(t *testing.T) {
})
}
func Test_Apply_dry_run(t *testing.T) {
test.WithApp(t, "/app", func(a *amocks.App, fs afero.Fs) {
applyConfig := ApplyConfig{
App: a,
ClientConfig: &client.Config{},
DryRun: true,
}
setupApp := func(apply *Apply) {
obj := &unstructured.Unstructured{Object: genObject()}
apply.clientOpts = &clientOpts{}
apply.findObjectsFn = func(a app.App, envName string, componentNames []string) ([]*unstructured.Unstructured, error) {
objects := []*unstructured.Unstructured{obj}
return objects, nil
}
apply.ksonnetObjectFactory = func() ksonnetObject {
return &fakeKsonnetObject{
obj: obj,
}
}
apply.upserterFactory = func() Upserter {
return &fakeUpserter{
upsertErr: errors.New("upsert should not run"),
}
}
}
err := RunApply(applyConfig, setupApp)
require.NoError(t, err)
})
}
func Test_Apply_retry_on_conflict(t *testing.T) {
test.WithApp(t, "/app", func(a *amocks.App, fs afero.Fs) {
applyConfig := ApplyConfig{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment