k8s-cluster-bundle

module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: Apache-2.0

README

Cluster Bundle

GoDoc

Note: This is not an officially supported Google product

The Cluster Bundle is a Kubernetes-related project developed to improve the way we package and release Kubernetes software. It was created by the Google Kubernetes team, and was developed based on our experience managing Kubernetes clusters and applications at scale in both GKE and GKE On-Prem.

It is currently experimental and will have likely have frequent, breaking changes for a while until the API settles down.

An Introduction to Packaging in the Cluster Bundle

Packaging in the cluster bundle revolves around a new type, called the Component Package:

  • Component Package: A versioned collection of Kubernetes objects. This should correspond to a logical application.
  • Component Set: A set of references to Component Packages.

The Cluster Bundle APIs are minimal and focused. In particular, they are designed to represent Kubernetes components without worrying about deployment. It is assumed that external deployment mechanisms like a command line interface or a deployment controller will consume the components and apply the components to a cluster.

Component Packages

In the wild, component packages look something like the following:

apiVersion: 'bundle.gke.io/v1alpha1'
kind: ComponentPackage
spec:
  # A human readable name for the component. The combination of name + version
  # should be unique in a cluster.
  componentName: etcd-component

  # Version of the component, representing changes to the manifest (like a flag
  # change) or the to container image[s].
  version: 30.0.2

  # Kubernetes objects that make up this component.
  objectFiles:
  - url: 'file://etcd-server.yaml'

All cluster objects can be inlined, which means they are imported directly into the component, which allows the component package to hermetically describe the component. After inlining, the component might look like:

apiVersion: 'bundle.gke.io/v1alpha1'
kind: ComponentPackage
spec:
  componentName: etcd-component
  version: 30.0.2
  objects:
  - apiVersion: v1
    kind: Pod
    metadata:
      name: etcd-server
      namespace: kube-system
    spec:
      containers:
      - command:
        - /bin/sh
        - -c
        - |
          exec /usr/local/bin/etcd
    # and so on

Additionally, raw text can be imported into a component package. When inlined, this text is converted into a config map and then added to the objects list:

apiVersion: bundle.gke.io/v1alpha1
kind: ComponentPackage
spec:
  canonicalName: data-blob
  version: 0.1.0
  rawTextFiles:
  - url: 'file://some-data.txt'
ComponentSets

Component Sets are collections of components, which makes it possible publish, validate, and deploy components as a single unit.

apiVersion: 'bundle.gke.io/v1alpha1'
kind: ComponentSet
spec:
  version: '2.3.4'

  components:
  - etcd-server-30.0.2
  - data-blob-0.1.0

Bundle CLI (bundlectl)

bundlectl is the name for the command line interface and is the standard way for interacting with components and component sets

Install with go install github.com/GoogleCloudPlatform/k8s-cluster-bundle/cmd/bundlectl

Validation

Components and ComponentSets have various constraints that must be validated. For functions in the library to work, the components are generalled assumed to have already been validated. For the ease of validating collections of components, the Bundle CLI knows about a type called ComponentData and has the form:

componentFiles:
- url: <component>

And so, in the examples directory, you will see:

componentFiles:
- url: 'file://etcd/etcd-component.yaml'
- url: 'file://nodes/nodes-component.yaml'
- url: 'file://kubernetes/kubernetes-component.yaml'
- url: 'file://kubedns/kubedns-component.yaml'
- url: 'file://kubeproxy/kube-proxy-component.yaml'
- url: 'file://datablob/data-blob-component.yaml'

To validate component data, run:

bundlectl validate -f <component-data>
Inlining

Inlining pulls files from the various URLs and imports the contents directly into the component. To inline component data, run:

bundlectl inline -f <component-data>
Filtering

Filtering allows removal of components and objects from the bundle.

# Filter all config map objects
bundlectl filter -f <component-data> --kind=ConfigMap

# Keep only config map objects.
bundlectl filter -f <component-data> --kind=ConfigMap --keep-only

Development

Directory Structure

This directory should follow the structure the standard Go package layout specified in https://github.com/golang-standards/project-layout

  • pkg/: Library code.
  • examples/: Examples of components and component packages.
  • pkg/apis: APIs and schema for the Cluster Bundle.
  • cmd/: Binaries. In particular, this contains the bundler CLI which assists in modifying and inspecting Bundles.
Building and Testing

The Cluster Bundle relies on Bazel for building and testing, but the library is go-gettable and it works equally well to use go build and go test for building and testing.

Testing

To run the unit tests, run

bazel test ...

Or, it should work fine to use the go command

go test ./...
Regenerate BUILD files

To make using Bazel easier, we use Gazelle to automatically write Build targets. To automatically write the Build targets, run:

bazel run //:gazelle
Regenerate Generated Code

We rely heavily on Kubernetes code generation. To regenerate the code, run:

hacke/update-codegen.sh

If new files are added, will to re-run Gazelle (see above).

Directories

Path Synopsis
cmd
bundlectl
Command bundlectl is used for modifying bundles.
Command bundlectl is used for modifying bundles.
pkg
apis
Package apis represents the directory for bundle APIs.
Package apis represents the directory for bundle APIs.
apis/bundle
Package bundle contains the internal APIs for the bundle.
Package bundle contains the internal APIs for the bundle.
apis/bundle/v1alpha1
Package v1alpha1 represents the v1alpha1 version of the Cluster Bundle API.
Package v1alpha1 represents the v1alpha1 version of the Cluster Bundle API.
apis/bundleext
Package bundleext is the internal version of the bundle extensions API.
Package bundleext is the internal version of the bundle extensions API.
apis/bundleext/v1alpha1
Package v1alpha1 represents the v1alpha1 version of extenisons for the Cluster Bundle API.
Package v1alpha1 represents the v1alpha1 version of extenisons for the Cluster Bundle API.
clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
clientset/versioned/typed/bundle/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
clientset/versioned/typed/bundle/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.
commands
Package commands contains commands used in the bundler command
Package commands contains commands used in the bundler command
commands/cmdlib
Package cmdlib contains shared functions for the bundle CLI commands.
Package cmdlib contains shared functions for the bundle CLI commands.
commands/filter
Package filter contains commands for filtering components and objects.
Package filter contains commands for filtering components and objects.
converter
Package converter provides utilities for converting between various types.
Package converter provides utilities for converting between various types.
core
Package core represents foundational data types that are used throughout the library, but are not part of the API.
Package core represents foundational data types that are used throughout the library, but are not part of the API.
files
Package files contains methods and data types for manipulating files.
Package files contains methods and data types for manipulating files.
filter
Package filter contains methods for filtering bundles.
Package filter contains methods for filtering bundles.
find
Package find provides methods for searching through Bundles the contained components and configuration.
Package find provides methods for searching through Bundles the contained components and configuration.
inline
Package inline turns
Package inline turns
options
Package options provides functionality for adding options to components.
Package options provides functionality for adding options to components.
options/rawyamltmpl
Package rawtexttmpl is a special-case option applier for adding options to objects with the assumption that objects have been inlined as go-templates via RawTextFiles ComponentPackageSpec field into ConfigMaps.
Package rawtexttmpl is a special-case option applier for adding options to objects with the assumption that objects have been inlined as go-templates via RawTextFiles ComponentPackageSpec field into ConfigMaps.
options/simpletemplate
Package simpletemplate contains helpers for applying options with the assumption that cluster objects are simple go templates.
Package simpletemplate contains helpers for applying options with the assumption that cluster objects are simple go templates.
scheme
Package scheme containts library functions for creating/managing Kubernetes schemes.
Package scheme containts library functions for creating/managing Kubernetes schemes.
testutil
Package testutil provides utilities for reading testdata from children directories.
Package testutil provides utilities for reading testdata from children directories.
transformer
Package transformer provides transformations for bundles
Package transformer provides transformations for bundles
validate
Package validate provides validation for types in the cluster bundle repository.
Package validate provides validation for types in the cluster bundle repository.

Jump to

Keyboard shortcuts

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