Skip to content

Commit

Permalink
don't update configmap while diff-run
Browse files Browse the repository at this point in the history
  • Loading branch information
sethiyash committed May 12, 2022
1 parent 72440b4 commit 9ecf7ac
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (a *RecordedApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) e

if foundMigratedApp {
a.isMigrated = true
return a.updateApp(app, labels)
return a.updateApp(app, labels, isDiffRun)
}

app, foundNonMigratedApp, err := a.find(a.name)
Expand All @@ -146,10 +146,10 @@ func (a *RecordedApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) e
}

if foundNonMigratedApp {
if a.isMigrationEnabled() {
if a.isMigrationEnabled() && !isDiffRun {
return a.migrate(app, labels, a.fqName())
}
return a.updateApp(app, labels)
return a.updateApp(app, labels, isDiffRun)
}

return a.create(labels, isDiffRun)
Expand Down Expand Up @@ -201,20 +201,26 @@ func (a *RecordedApp) create(labels map[string]string, isDiffRun bool) error {
if isDiffRun {
createOpts.DryRun = []string{metav1.DryRunAll}
}

app, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), configMap, createOpts)

a.setMeta(*app)

return err
}

func (a *RecordedApp) updateApp(existingConfigMap *corev1.ConfigMap, labels map[string]string) error {
func (a *RecordedApp) updateApp(existingConfigMap *corev1.ConfigMap, labels map[string]string, isDiffRun bool) error {
err := a.mergeAppUpdates(existingConfigMap, labels)
if err != nil {
return err
}

_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Update(context.TODO(), existingConfigMap, metav1.UpdateOptions{})
updateOpts := metav1.UpdateOptions{}
if isDiffRun {
updateOpts.DryRun = []string{metav1.DryRunAll}
}

_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Update(context.TODO(), existingConfigMap, updateOpts)
if err != nil {
return fmt.Errorf("Updating app: %s", err)
}
Expand All @@ -232,7 +238,7 @@ func (a *RecordedApp) RenamePrevApp(prevAppName string, labels map[string]string

if foundMigratedApp {
a.isMigrated = true
return a.updateApp(app, labels)
return a.updateApp(app, labels, isDiffRun)
}

app, foundNonMigratedApp, err := a.find(a.name)
Expand All @@ -241,10 +247,10 @@ func (a *RecordedApp) RenamePrevApp(prevAppName string, labels map[string]string
}

if foundNonMigratedApp {
if a.isMigrationEnabled() {
if a.isMigrationEnabled() && !isDiffRun {
return a.migrate(app, labels, a.fqName())
}
return a.updateApp(app, labels)
return a.updateApp(app, labels, isDiffRun)
}

app, foundMigratedPrevApp, err := a.find(prevAppName + AppSuffix)
Expand All @@ -263,7 +269,7 @@ func (a *RecordedApp) RenamePrevApp(prevAppName string, labels map[string]string
}

if foundNonMigratedPrevApp {
if a.isMigrationEnabled() {
if a.isMigrationEnabled() && !isDiffRun {
return a.migrate(app, labels, a.fqName())
}
return a.renameConfigMap(app, a.name, a.nsName)
Expand Down

0 comments on commit 9ecf7ac

Please sign in to comment.