Skip to content

Commit

Permalink
rebased and refactored after trim suffix changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sethiyash committed Apr 28, 2022
1 parent 4e1e8f7 commit d286d17
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,26 @@ func (a *RecordedApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) e
}
}

return a.createOrUpdate(configMap, labels)
return a.createOrUpdate(configMap, labels, isDiffRun)
}
}

return fmt.Errorf("Getting app: %s", err)
}

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

_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), c, metav1.CreateOptions{})
var dryRunValue []string = nil

if isDiffRun {
dryRunValue = []string{metav1.DryRunAll}
}

app, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), c, metav1.CreateOptions{DryRun: dryRunValue})
if err != nil {
if errors.IsAlreadyExists(err) {
existingConfigMap, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(context.TODO(), c.GetObjectMeta().GetName(), metav1.GetOptions{})
Expand All @@ -197,6 +203,10 @@ func (a *RecordedApp) createOrUpdate(c *corev1.ConfigMap, labels map[string]stri
return fmt.Errorf("Creating app: %s", err)
}

if isDiffRun {
a.setMeta(*app)
}

return nil
}

Expand All @@ -214,7 +224,7 @@ func (a *RecordedApp) updateApp(existingConfigMap *corev1.ConfigMap, labels map[
return nil
}

func (a *RecordedApp) RenamePrevApp(prevAppName string, labels map[string]string) error {
func (a *RecordedApp) RenamePrevApp(prevAppName string, labels map[string]string, isDiffRun bool) error {
defer a.logger.DebugFunc("RenamePrevApp").Finish()
var c *corev1.ConfigMap
var err error
Expand Down Expand Up @@ -269,7 +279,7 @@ func (a *RecordedApp) RenamePrevApp(prevAppName string, labels map[string]string
return err
}
}
return a.createOrUpdate(newConf, labels)
return a.createOrUpdate(newConf, labels, isDiffRun)
}
}
}
Expand Down

0 comments on commit d286d17

Please sign in to comment.