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

Develop Component resource for: kubernetes:kustomize:Directory #3036

Merged
merged 6 commits into from
May 31, 2024

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented May 30, 2024

Proposed changes

This PR implements the Kustomize Directory resource (v2) as a multi-language component resource.

The Directory resource creates child resources based on a kustomization directory. The input is a path to a directory containing 'kustomization.yaml', or a git repository URL with a path suffix and other qualifiers.

Related issues (optional)

Closes #2786

API

property description
directory The directory or git URL containing the kustomization to apply.
namespace Overrides the default namespace.
skipAwait Applies the skipAwait annotation.
resourcePrefix Prefix for child resources, defaults to the component name.

Feature: Remote Targets

This implementation supports remote kustomization targets as described here.

Note: the v1 implementation also supports git references, but resolves them using the Pulumi SDK (RetrieveGitFolder) rather than using Kustomize's own implementation. This is to ensure a consistent experience for nested git targets and to support git authentication.

Feature: Enable Alpha Plugins

This implementation always enables Kustomize's plugin support, akin to kustomize build --enable-alpha-plugins.

Plugins are drawn from KUSTOMIZE_PLUGIN_HOME (default: ~/.config/kustomize/plugin/). Note: the kustomize library doesn't allow for easy customization of the plugin home.

Feature: Unrestricted Loading

Kustomize has a strict and a relaxed mode with respect to path references outside the kustomization base directory (--load-restrictor, default is strict). The feature seems intended to encourage portability, similarly to paths in Dockerfiles. This implementation simply enables the relaxed mode.

Feature: Enable Helm Charts

This implementation enables Helm chart support in Kustomize, which is an experimental feature of Directory v1 (see: #2470). Note that chart support in Kustomize is limited and evolving; see kubernetes-sigs/kustomize#4401 for the long-term support plan.

The helm binary is assumed to be on the path.

Feature: Namespace Override

New to v2 is support for overriding the default namespace (default is from provider configuration), as a convenience. Kustomize itself has a similar facility (see: namespace) but it makes sense to support it natively.

Feature: Resource Ordering

The Directory resource uses Pulumi's engine to install the resources produced by kustomize. It automatically detects dependencies between some resources. For example, it knows to install namespaces and Custom Resource Definitions (CRDs) first.

Use the config.kubernetes.io/depends-on annotation to declare an explicit resource dependency. See blog post for more info.

Limitation: Kubernetes-Style Transformations

The older v1 implementation provides the ability to transform the Kubernetes objects produced by kustomize before being sent to the server. That feature isn't available in Directory v2 at this time. You may still use Pulumi's transform option to modify the child resources.

Tests

The PR includes unit tests covering the provider implementation code.

Also includes an integration test that is similar to the below example.

Example

Here's an example of deploying a couple of kustomizations. The local kustomization (see: helloWorld for details) shows how to use a variable to select a kustomization overlay.

name: issue-2786-yaml
runtime: yaml
description: |
  Demonstrates the Directory resource.
  Reference: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
config:
  variant:
    type: string
    default: staging
outputs:
  name: ${local.resources}
resources:
  ns:
    type: kubernetes:core/v1:Namespace
  local:
    type: kubernetes:kustomize/v2:Directory
    properties:
      namespace: ${ns.metadata.name}
      directory: ./config/${variant}
      skipAwait: true
  remote:
    type: kubernetes:kustomize/v2:Directory
    properties:
      namespace: ${ns.metadata.name}
      directory: https://github.com/kubernetes-sigs/kustomize//examples/helloWorld/?ref=v3.3.1
      skipAwait: true

@EronWright EronWright changed the title Eronwright/issue 2876 kustomize Develop Component resource for: kubernetes:kustomize:Directory May 30, 2024
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.

New resources:

  • kustomize/v2.Directory

Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 55.05618% with 40 lines in your changes are missing coverage. Please review.

Project coverage is 36.64%. Comparing base (4eaacba) to head (dd6fee1).

Files Patch % Lines
provider/pkg/provider/kustomize/v2/directory.go 61.53% 22 Missing and 8 partials ⚠️
provider/pkg/gen/schema.go 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3036      +/-   ##
==========================================
+ Coverage   36.45%   36.64%   +0.18%     
==========================================
  Files          70       71       +1     
  Lines        9167     9249      +82     
==========================================
+ Hits         3342     3389      +47     
- Misses       5496     5522      +26     
- Partials      329      338       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EronWright EronWright force-pushed the eronwright/issue-2876-kustomize branch from b541bb2 to 008e888 Compare May 30, 2024 21:11
@EronWright EronWright marked this pull request as ready for review May 30, 2024 21:23
@EronWright EronWright force-pushed the eronwright/issue-2876-kustomize branch from 008e888 to 33c8a0b Compare May 30, 2024 21:23
@EronWright EronWright requested review from a team and lblackstone May 30, 2024 21:24
provider/pkg/gen/overlays.go Outdated Show resolved Hide resolved
provider/pkg/provider/kustomize/v2/directory_test.go Outdated Show resolved Hide resolved
@EronWright EronWright requested a review from rquitales May 31, 2024 17:51
@EronWright EronWright enabled auto-merge (squash) May 31, 2024 18:06
@rquitales
Copy link
Member

Second pass of the PR looks good. I'd prefer if we could also include a integration test flow to ensure that we can actually create these resources.

@EronWright EronWright merged commit 4fddc20 into master May 31, 2024
18 checks passed
@EronWright EronWright deleted the eronwright/issue-2876-kustomize branch May 31, 2024 19:45
@EronWright EronWright mentioned this pull request Jun 4, 2024
EronWright added a commit that referenced this pull request Jun 4, 2024
### Added
- Kustomize Directory v2 resource
(#3036)
- CustomResource for Java SDK
(#3020)

### Changed
- Update to pulumi-java v0.12.0
(#3025)

### Fixed
- Fixed Chart v4 fails on update
(#3046)
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v4.13.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Develop Component resource for: kubernetes:kustomize:Directory
3 participants