Created
July 25, 2021 07:41
-
-
Save aaronjwood/eac5fe76357cbb845260925abd466570 to your computer and use it in GitHub Desktop.
Apply method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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