crdutil

package
v0.0.0-...-00b15b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

CRD Apply Tool

This tool is designed to help deploy and manage Custom Resource Definitions (CRDs) in a Kubernetes cluster. It applies all CRDs found in specified directories, providing a solution to some of the limitations of Helm when it comes to managing CRDs.

Motivation

While Helm is commonly used for managing Kubernetes resources, it has certain restrictions with CRDs:

  • CRDs placed in Helm's top-level crds/ directory are not updated on upgrades or rollbacks.
  • Placing CRDs in Helm’s templates/ directory is not entirely safe, as deletions and upgrades of CRDs are not always handled properly.

This tool offers a more reliable way to apply CRDs, ensuring they are created or updated as needed.

Features

  • Apply CRDs from multiple directories: Allows specifying multiple directories containing CRD YAML manifests.
  • Recursive directory search: Walks through each specified directory to find and apply all YAML files.
  • Safe update mechanism: Checks if a CRD already exists; if so, it updates it with the latest version.
  • Handles multiple YAML documents: Supports files containing multiple CRD documents separated by YAML document delimiters.

Usage

Compile and run the tool by providing the -crds-dir flag with paths to the directories containing the CRD YAML files:

go build -o crd-apply-tool
./crd-apply-tool -crds-dir /path/to/crds1 -crds-dir /path/to/crds2

In a Helm pre-install hook it can look like:

apiVersion: batch/v1
kind: Job
metadata:
  name: upgrade-crd
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "1"
    "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
spec:
  template:
    metadata:
      name: upgrade-crd
    spec:
      containers:
        - name: upgrade-crd
          image: path-to-your/crd-apply-image
          imagePullPolicy: IfNotPresent
          command:
            - /apply-crds
          args:
              - --crds-dir=/crds/operator

Note: the image must contain all your CRDs in e.g. the /crds/operator directory.

Flags

  • -crds-dir (required): Specifies a directory path that contains the CRD manifests in YAML format. This flag can be provided multiple times to apply CRDs from multiple directories.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureCRDsCmd

func EnsureCRDsCmd()

EnsureCRDsCmd reads each YAML file in the directory, splits it into documents, and applies each CRD to the cluster. The parameter --crds-dir is required and should point to the directory containing the CRD manifests.

Types

type StringList

type StringList []string

func (*StringList) Set

func (s *StringList) Set(value string) error

func (*StringList) String

func (s *StringList) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL