Apply objects one by one so that one redeploy won't force delete all objects
@@ -58,19 +58,20 @@ func (c *CLI) Apply(ctx context.Context, out io.Writer, manifests ManifestList)
if len(updated) == 0 {
return nil, nil
}
-
+ for _, mfst := range manifests {
buf := bytes.NewBuffer([]byte{})
writer := bufio.NewWriter(buf)
- if err := c.Run(ctx, manifests.Reader(), writer, "apply", c.Flags.Apply, "-f", "-"); err != nil {
+ ml := ManifestList{mfst}
+ if err := c.Run(ctx, ml.Reader(), writer, "apply", c.Flags.Apply, "-f", "-"); err != nil {
if !strings.Contains(buf.String(), "field is immutable") {
return nil, err
}
// If the output contains the string 'field is immutable', we want to delete the object and recreate it
// See Issue #891 for more information
- if err := c.Delete(ctx, out, manifests); err != nil {
+ if err := c.Delete(ctx, out, ml); err != nil {
return nil, errors.Wrap(err, "deleting manifest")
}
- if err := c.Run(ctx, manifests.Reader(), out, "apply", c.Flags.Apply, "-f", "-"); err != nil {
+ if err := c.Run(ctx, ml.Reader(), out, "apply", c.Flags.Apply, "-f", "-"); err != nil {
return nil, errors.Wrap(err, "kubectl apply after deletion")
}
} else {
@@ -79,7 +80,7 @@ func (c *CLI) Apply(ctx context.Context, out io.Writer, manifests ManifestList)
return nil, errors.Wrap(err, "writing to out")
}
}
-
+ }
return updated, nil
}
