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

Challenges with setting namespace when using generators #2466

Open
howardjohn opened this issue Aug 25, 2021 · 0 comments
Open

Challenges with setting namespace when using generators #2466

howardjohn opened this issue Aug 25, 2021 · 0 comments
Labels
area/fn-sdk Typescript SDK area/hydrate enhancement New feature or request p1 triaged Issue has been triaged by adding an `area/` label

Comments

@howardjohn
Copy link
Contributor

Describe your problem

I am trying to write a generator function. Basically it inserts some data into a configmap, nothing too fancy.

My Kptfile looks like:

pipeline:
  mutators:
    - image: my-generator
      configMap:
        data: "..."
   - image: gcr.io/kpt-fn/set-namespace:v0.1
     configMap:
       namespace: grafana

My function generates a new config, and inserts it into the list of items with merging:

	rl.Items = append(rl.Items, yaml.NewRNode(&node))
	rl.Items, err = filters.MergeFilter{}.Filter(rl.Items)

The problem is that the generator doesn't add a namespace, but then it later is added. This means that the second run of the pipeline ends up appending the config again - so we end up with 2x copies.

Possible solutions:

  • Generator functions should not include namespace on merge key. This seems prone to failure in cases of multiple namespaces handled by one Kptfile
  • Generator functions should always explicit set the namespace. This requires all generators to take a namespace param, and all usages to set it as well - a lot of churn and duplication.
  • When configMap is used, set the namespace equal to that of the Kptfile namespace. Bonus points if set-namespace also uses this. Then, the whole Kptfile could look like:
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
  name: grafana
  namespace: grafana
pipeline:
  mutators:
    - image: my-generator
      configMap:
        data: "..."
   - image: gcr.io/kpt-fn/set-namespace:v0.1
     configMap: {}

To get the namespace that should be used, functions can use rl.FunctionConfig.GetNamespace()

  • if set-namespaces generates a duplicate resource, it could filter one of them out. This feels like the wrong solution - especially if it picks the wrong copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/fn-sdk Typescript SDK area/hydrate enhancement New feature or request p1 triaged Issue has been triaged by adding an `area/` label
Projects
None yet
Development

No branches or pull requests

2 participants