Skip to content

Instantly share code, notes, and snippets.

@aaronjwood
Created July 25, 2021 07:41
Show Gist options
  • Save aaronjwood/eac5fe76357cbb845260925abd466570 to your computer and use it in GitHub Desktop.
Save aaronjwood/eac5fe76357cbb845260925abd466570 to your computer and use it in GitHub Desktop.
Apply method
// Apply takes parsed resources and applies them into a cluster.
func Apply(ctx context.Context, resources ...*Resource) error {
for _, resource := range resources {
_, createErr := resource.Action.Create(ctx, resource.Unstruct, metav1.CreateOptions{})
if createErr != nil {
if apiErrs.IsAlreadyExists(createErr) {
updateErr := Update(ctx, resource)
if updateErr != nil {
return updateErr
}
} else {
return createErr
}
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment