jpl

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

jpl

Go Report Card Go Package Reference Site

JPL is a library to simplify the application of a series of kuberntes resources saved on files to a remote cluster.
It also add some nice to have features that lacks in kubectl:

  • resources ordering
  • automatic waiting of current statuses
  • generating new resources from manifests
  • check if flowcontrol api is enabled on the remote cluster
  • keep inventory of applied resoruces for automatic pruning

The fastest way to add this library to a project is to run go get github.com/mia-platform/jpl@latest with go1.16+

Table of Contents

What's included
  • the client package contains the client to apply the resources to a Kubernetes API server
  • the event package contains the various events that the client will return to tell the user what is happening
  • the filter package contain a filter interface for omit resources from the current apply action
  • the flowcontrol package contains the checks necessary to know if the Kubernetes API server has the flowcontrol enabled
  • the generator package contain built-in generators that can be used to generate new resources from other manifests
  • the inventory package is used to keep track of the resources deployed in precedent apply to compute the necessary pruning actions
  • the mutator package contain built-in mutators that can be used to modify resources before applying them
  • the resource package contains useful utils function to work with Unstructured data
  • the resourcereader package is useful for parsing valid kubernetes resource manifests from a folder of yaml file or via stdin
  • the runner package contains a queue like executor of a series of tasks sequentially
  • the testing package contains utils for testing the other packages
  • the util package contains utility resources
Features
Pruning

The Applier automatically deletes objects that were previously applied and then removed from the input set on a subsequent apply.

The current implementation of kubectl apply --prune is an alpha, and it is improbable that it will graduate to beta. jpl attempts to address the current deficiencies by storing the set of previously applied objects in an inventory object which is applied to the cluster. The reference implementation uses a ConfigMap as an inventory object and references to the applied objects are stored in the data section of the ConfigMap that is generated and recovered at every run.

Waiting for Reconciliation

The Applier automatically watches applied objects and tracks their status, blocking until the objects have reconciled or failed.

This functionality is similar to kubectl delete <resource> <name> --wait, in that it waits for all finalizers to complete, except it works for creates and updates.

While there is a kubectl apply <resource> <name> --wait, it only waits for deletes when combined with --prune. jpl provides an alternative that works for all spec changes, waiting for reconciliation, the convergence of status to the desired specification. After reconciliation, it is expected that the object has reached a steady state until the specification is changed again.

Resource Ordering

The Applier use resource type to determine which order to apply and delete objects.

In contrast, when using kubectl apply, the objects are applied in alphanumeric order of their file names, and top to bottom in each file. With jpl, this manual sorting is unnecessary for many common use cases.

Implicit Dependency Ordering

jpl automatically detects some implicit dependencies that includes:

  1. Namespace-scoped resource objects depend on their Namespace
  2. Custom resource objects depend on their Custom Resource Definition
  3. Validation and Mutating Webhooks depends on their Services

Like resource ordering, implicit dependency ordering improves the apply and delete experience to reduce the need to manually specify ordering for many common use cases. This allows more objects to be applied together all at once, with less manual orchestration.

Explicit Dependency Ordering

In addition to implicit dependencies sometimes the user would like to determine certain resources ordering. In these cases, the user can use explicit dependency ordering by adding a config.kubernetes.io/depends-on: <OBJECT_REFERENCE> annotation to an object.

The Applier use these explicit dependency directives to build a dependency tree and flatten it for determining apply ordering.

In addition to ordering the applies, dependency ordering also waits for dependency reconciliation when applying. This ensures that dependencies are not just applied first, but have reconciled before their dependents are applied.

In the following example, the config.kubernetes.io/depends-on annotation identifies that nginx must be successfully applied prior to workload actuation:

apiVersion: v1
kind: Pod
metadata:
  name: workload
  annotations:
    config.kubernetes.io/depends-on: /namespaces/default/Pod/nginx
spec:
  containers:
    - name: workload
      image: registry.k8s.io/pause:2.0
Compatibility: jpl <-> Kubernetes clusters

Since jpl will use the Kuberntes packages to execute calls, every version of the library is compatible with the versions of Kubernetes that are compatible with them.

Compatibility matrix
Kubernetes 1.24 Kubernetes 1.25 Kubernetes 1.26 Kubernetes 1.27 Kubernetes 1.28 Kubernetes 1.29 Kubernetes 1.30
jpl-0.1.x +- +- +- +- +- +-
jpl-0.2.x +- +- +- +- +- +-
jpl-0.3.x +- +- +- +- +- +-
jpl-0.4.x +- +- +- +- +- +-
HEAD +- +- +- +- +- +-

Key:

  • the Kubernetes version officially sypported by the packages versions
  • + kubernetes packages can have features or API objects that may not be present in the Kubernetes cluster, either due to that client-go has additional new API, or that the server has removed old API. However, everything they have in common (i.e., most APIs) will work. Please note that alpha APIs may vanish or change significantly in a single release.
  • - The Kubernetes cluster has features that the kubernetes packages can't use, either due to the server has additional new API, or that client-go has removed old API. However, everything they share in common (i.e., most APIs) will work.

See the CHANGELOG for a detailed description of changes between jpl versions.

How to get it

To get the latest version, use go1.16+ and fetch using the go get command. For example:

go get github.com/mia-platform/jpl@latest

To get a specific version, use go1.11+ and fetch the desired version using the go get command. For example:

go get github.com/mia-platform/jpl@v0.2.0

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
client/cache
cache package contains a RemoteResourceGetter interface for retrieving remote resource state without exposing the underline clients implementation.
cache package contains a RemoteResourceGetter interface for retrieving remote resource state without exposing the underline clients implementation.
event
event package contains the event structure to encapsulate what is happening during the client apply process.
event package contains the event structure to encapsulate what is happening during the client apply process.
filter
filter package provide an interface for filtering resources during apply time.
filter package provide an interface for filtering resources during apply time.
flowcontrol
flowcontrol package implement a call to a well known endpoint of a Kubernetes api-server for extracting information about the availability of server side flow control.
flowcontrol package implement a call to a well known endpoint of a Kubernetes api-server for extracting information about the availability of server side flow control.
generator
generator package provide an interface for creating custom resources from the provided one.
generator package provide an interface for creating custom resources from the provided one.
inventory
inventory package contains structures and functions for generating an "inventory" of resource managed by the tool.
inventory package contains structures and functions for generating an "inventory" of resource managed by the tool.
inventory/fake
fake package provide a fake implementation of an inventory Store for using during tests.
fake package provide a fake implementation of an inventory Store for using during tests.
mutator
mutator package provide an interface for mutating resources.
mutator package provide an interface for mutating resources.
poller
poller package contains the implementation of status poller for monitoring a set of resources on the remote server and posting their updates in a channel
poller package contains the implementation of status poller for monitoring a set of resources on the remote server and posting their updates in a channel
resource
resource package contains utility functions for working on Unstructured data
resource package contains utility functions for working on Unstructured data
resourcereader
resourcereader package contains functions for reading, parsing and ordering kubernetes manifests from files or stdin.
resourcereader package contains functions for reading, parsing and ordering kubernetes manifests from files or stdin.
runner
runner package contains the implementation of a queue of tasks that can perfom actions against a remote api-server
runner package contains the implementation of a queue of tasks that can perfom actions against a remote api-server
runner/task
task package contains Tasks implementation that encapsulate actions against an api-server
task package contains Tasks implementation that encapsulate actions against an api-server
testing
testing package provides structure and functions useful for create test and have predictable outcome or avoid to call real external dependencies
testing package provides structure and functions useful for create test and have predictable outcome or avoid to call real external dependencies
util
util package provides utility functions for other packages
util package provides utility functions for other packages

Jump to

Keyboard shortcuts

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