Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding optional git manifest delete. #650

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/bootstrap_git.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The following examples are available to help you use the provider:
- `cluster_domain` (String) The internal cluster domain. Defaults to `cluster.local`
- `components` (Set of String) Toolkit components to include in the install manifests. Defaults to `[source-controller kustomize-controller helm-controller notification-controller]`
- `components_extra` (Set of String) List of extra components to include in the install manifests.
- `delete_git_manifests` (Boolean) Delete manifests from git repository. Defaults to `true`.
- `disable_secret_creation` (Boolean) Use the existing secret for flux controller and don't create one from bootstrap
- `image_pull_secret` (String) Kubernetes secret name used for pulling the toolkit images from a private registry.
- `interval` (String) Interval at which to reconcile from bootstrap repository. Defaults to `1m0s`.
Expand Down
33 changes: 22 additions & 11 deletions internal/provider/resource_bootstrap_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,28 @@ const (
)

type bootstrapGitResourceData struct {
ID types.String `tfsdk:"id"`
Version types.String `tfsdk:"version"`
Path types.String `tfsdk:"path"`
ClusterDomain types.String `tfsdk:"cluster_domain"`
Components types.Set `tfsdk:"components"`
ComponentsExtra types.Set `tfsdk:"components_extra"`
DeleteGitManifests types.Bool `tfsdk:"delete_git_manifests"`
DisableSecretCreation types.Bool `tfsdk:"disable_secret_creation"`
ID types.String `tfsdk:"id"`
ImagePullSecret types.String `tfsdk:"image_pull_secret"`
Interval customtypes.Duration `tfsdk:"interval"`
KustomizationOverride types.String `tfsdk:"kustomization_override"`
LogLevel types.String `tfsdk:"log_level"`
ManifestsPath types.String `tfsdk:"manifests_path"`
Namespace types.String `tfsdk:"namespace"`
NetworkPolicy types.Bool `tfsdk:"network_policy"`
Registry customtypes.URL `tfsdk:"registry"`
TolerationKeys types.Set `tfsdk:"toleration_keys"`
WatchAllNamespaces types.Bool `tfsdk:"watch_all_namespaces"`
Interval customtypes.Duration `tfsdk:"interval"`
SecretName types.String `tfsdk:"secret_name"`
DisableSecretCreation types.Bool `tfsdk:"disable_secret_creation"`
Path types.String `tfsdk:"path"`
RecurseSubmodules types.Bool `tfsdk:"recurse_submodules"`
KustomizationOverride types.String `tfsdk:"kustomization_override"`
Registry customtypes.URL `tfsdk:"registry"`
RepositoryFiles types.Map `tfsdk:"repository_files"`
SecretName types.String `tfsdk:"secret_name"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
ManifestsPath types.String `tfsdk:"manifests_path"`
TolerationKeys types.Set `tfsdk:"toleration_keys"`
Version types.String `tfsdk:"version"`
WatchAllNamespaces types.Bool `tfsdk:"watch_all_namespaces"`
}

// Ensure provider defined types fully satisfy framework interfaces.
Expand Down Expand Up @@ -194,6 +195,10 @@ func (r *bootstrapGitResource) Schema(ctx context.Context, req resource.SchemaRe
setvalidator.ValueStringsAre(stringvalidator.OneOf("image-reflector-controller", "image-automation-controller")),
},
},
"delete_git_manifests": schema.BoolAttribute{
Description: "Delete manifests from git repository. Defaults to `true`.",
Optional: true,
},
"image_pull_secret": schema.StringAttribute{
Description: "Kubernetes secret name used for pulling the toolkit images from a private registry.",
Optional: true,
Expand Down Expand Up @@ -651,6 +656,12 @@ func (r bootstrapGitResource) Delete(ctx context.Context, req resource.DeleteReq
}

err = retry.RetryContext(ctx, timeout, func() *retry.RetryError {

if !(data.DeleteGitManifests.IsNull() || data.DeleteGitManifests.ValueBool()) {
tflog.Debug(ctx, "Skipping git repository removal", map[string]interface{}{})
return nil
}

gitClient, err := r.prd.GetGitClient(ctx)
if err != nil {
return retry.NonRetryableError(err)
Expand Down
Loading