pulumi / pulumi-kubernetes

A Pulumi resource provider for Kubernetes to manage API resources and workloads in running clusters
https://www.pulumi.com/docs/reference/clouds/kubernetes/
Apache License 2.0
406 stars 115 forks source link

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

Closed EronWright closed 4 months ago

EronWright commented 4 months ago

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: https://github.com/pulumi/pulumi-kubernetes/issues/2470). Note that chart support in Kustomize is limited and evolving; see https://github.com/kubernetes-sigs/kustomize/issues/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
github-actions[bot] commented 4 months ago

Does the PR have any schema changes?

Looking good! No breaking changes found.

New resources:

codecov[bot] commented 4 months ago

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 :warning:
provider/pkg/gen/schema.go 0.00% 10 Missing :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

rquitales commented 4 months ago

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.

pulumi-bot commented 2 months ago

This PR has been shipped in release v4.13.1.