Files
kustomize/bin/pluginator.sh
Jeffrey Regan 939de0cdbe Dogfood the plugin framework.
This PR:

* provides a code generator that converts
  kustomize Go plugins to normal code, i.e.
  the plugin appears as
    t := builtin.NewImageTagTransformer()
  instead of
    p := plugin.Open("imagetagtransformer.so")
    s := p.Lookup(someSymbol)
    t, ok = s.(Transformer)

* converts the main processing thread in
  kusttarget.go to use those factory calls to run
  builtin generators and transformer before
  calling user-supplied plugins,

* as an example, provides an imagetag transformer
  plugin, converting a legacy transformer to
  builtin plugin form with its own isolated test.
  This test can be expanded by moving more code
  into it, but that can be done in a later PR.

Writing core functionality as plugins assures a
maintained plugin authoring and testing framework,
assures modularity, provides meaningful plugin
examples, and gives us a means to make informed
choices on which kustomize packages to publish
(and which to move to internal/).  The code
generator allows all this without losing "go get
sigs.k8s.io/kustomize" functionality.

TODO:

  1) Convert remaining legacy transformers to
     plugins (patch SMP/JSON, name prefix/suffix,
     labels/annos) with their own tests.  The
     generators are already done; this PR wires
     them up, and all tests & examples pass.

  2) Push code down into the plugins, as the first
     pass at conversion writes plugins as thin
     layers over calls into code under the mess
     that is pkg/.  Once this is done, we can
     reasonably move all the packages that aren't
     imported by plugins to internal/.

This PR could be split in two, one to merge the
the generator, and the second to merge the
ImageTagTransformer plugin and its wiring into the
main flow.

The latter PR could then serve as an example for
converting the remaining transformers.
2019-05-16 10:07:28 -07:00

47 lines
944 B
Bash
Executable File

#!/bin/bash
#
# Converts Go-based kustomize plugins in
# sigs.k8s.io/kustomize/plugin/builtin
# (all in package 'main') to generator and
# transformer factory functions in
# sigs.k8s.io/kustomize/plugin/builtingen
# (all in package 'builtingen').
#
# Cannot put all these in the same dir, since
# plugins must be in the 'main' package,
# the factory functions cannot be in 'main',
# Go disallows multiple packages in one dir.
set -e
myGoPath=$1
if [ -z ${1+x} ]; then
myGoPath=$GOPATH
fi
if [ -z "$myGoPath" ]; then
echo "Must specify a GOPATH"
exit 1
fi
dir=$myGoPath/src/sigs.k8s.io/kustomize
if [ ! -d "$dir" ]; then
echo "$dir is not a directory."
exit 1
fi
echo Generating linkable plugins...
pushd $dir >& /dev/null
/bin/rm -rf plugin/builtingen
mkdir plugin/builtingen
GOPATH=$myGoPath go generate --tags plugin \
sigs.k8s.io/kustomize/plugin/builtin
ls -C1 plugin/builtingen
popd >& /dev/null
echo All done.