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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting filtering resources to be applied in YAML, Kustomize, Chart resources. #2879

Open
AaronFriel opened this issue Mar 13, 2024 · 0 comments

Comments

@AaronFriel
Copy link
Member

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

Using Transformations and a workaround for the following feature request, it's possible to filter the resources. This is however, a bit clumbsy.

It's a very common pattern when deploying large manifests that we need to deploy some resources before others or filter resources. For example, I might want to deploy all CRDs and namespaces first in one Pulumi resource, then deploy all of their dependencies via a second.

With the upcoming release of yaml/v2.ConfigFile and yaml/v2.ConfigGroup, the following workaround won't work.

Current behavior

Here's an example of how I use this to filter the CRDs, to apply them first:

const crds = new k8s.kustomize.Directory(
  `${name}-crds`,
  {
    directory: './kubeflow', // relative to Pulumi project root
    transformations: [crdsOnly, skipAwait, patchForce],
  },
  { ...opts, retainOnDelete: true },
);
export function crdsOnly(obj: any, opts: pulumi.CustomResourceOptions): void {
  if (typeof obj === 'object' && obj !== null) {
    if (!objIsCrd(obj)) {
      removeItem(obj);
    }
  }
}

function objIsCrd(obj: object): boolean {
  return 'kind' in obj && obj.kind === 'CustomResourceDefinition';
}

// Workaround for Pulumi, this effectively removes it from the resources to apply
function removeItem(obj: any): void {
  for (const key of Object.keys(obj)) {
    if (key !== 'apiVersion' && key !== 'kind') {
      // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
      delete obj[key];
    }
  }
  obj.apiVersion = 'v1';
  obj.kind = 'List';
  obj.items = [];
}

Affected area/feature

@AaronFriel AaronFriel added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Mar 13, 2024
@mjeffryes mjeffryes added area/custom-resources and removed needs-triage Needs attention from the triage team labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants