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

Extend ssa.Apply with field ignore rules #696

Open
1 of 3 tasks
stefanprodan opened this issue Dec 1, 2023 · 1 comment
Open
1 of 3 tasks

Extend ssa.Apply with field ignore rules #696

stefanprodan opened this issue Dec 1, 2023 · 1 comment
Labels
area/server-side-apply SSA related issues and pull requests enhancement New feature or request

Comments

@stefanprodan
Copy link
Member

stefanprodan commented Dec 1, 2023

To make kustomize-controller compatible with VPA, HPA for custom resources and other controllers which mutate Flux-managed fields in-cluster, we need to wire the ssa/jsondiff logic into the SSA apply functions.

Tasks:

  • Move the saa functions used in jsondiff to a dedicated package
  • Add []jsondiff.IgnoreRule to the ssa.ApplyOptions
  • Remove the ignored fields before the final apply if they diverge

Example:

	appliedObject := object.DeepCopy()

	if existingObject.GetResourceVersion() != "" {
		var sm = make(map[*jsondiff.SelectorRegex][]string, len(opts.DriftIgnoreRule))
		for _, ips := range opts.DriftIgnoreRule {
			sr, err := jsondiff.NewSelectorRegex(ips.Selector)
			if err != nil {
				return nil, fmt.Errorf("failed to create ignore rule selector: %w", err)
			}
			sm[sr] = ips.Paths
		}

		var ignorePaths jsondiff.IgnorePaths
		for sr, paths := range sm {
			if sr.MatchUnstructured(appliedObject) {
				ignorePaths = append(ignorePaths, paths...)
			}
		}

		if len(ignorePaths) > 0 {
			patch := jsondiff.GenerateRemovePatch(ignorePaths...)
			if err := jsondiff.ApplyPatchToUnstructured(appliedObject, patch); err != nil {
				return nil, err
			}
		}
	}

	if err := m.apply(ctx, appliedObject); err != nil {
		return nil, fmt.Errorf("%s apply failed: %w", FmtUnstructured(appliedObject), err)
	}
@alxbse
Copy link

alxbse commented Oct 21, 2024

Would like to contribute to getting this solved as flux has been great for my use cases until I now need to manage a CRD with a conversion webhook and a cert-manager caBundle that would keep getting removed/added.

Is it "just" a lack of priority and contributions that is blocking this issue or is there something else related to adding the ignore rules that makes this extra complicated to solve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/server-side-apply SSA related issues and pull requests enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants