Skip to content

Commit

Permalink
WIP Expand bootstrap modules via remote assemblages
Browse files Browse the repository at this point in the history
At present, bootstrap modules get expanded directly into Flux
primitives (one GitRepository, and a Kustomization per
cluster). Incremental rollouts could be implemented within this
scheme; however, it would not help third party integrations much since
they'd have to implement all of it themselves. Instead, I'm
repurposing the RemoteAssemblage type -- the behaviour of which was
moved to the better-named ProxyAssemblage -- to represent a set of
syncs to be applied remotely to a cluster.

In this commit:

 - change the definition of the RemoteAssemblage type so it contains
   syncs to apply remotely, rather than syncs to proxy (those were
   moved to ProxyAssemblage)

 - move the "expand to Flux primitives" code from the bootstrap module
   controller to the remote assemblage controller

 - implement the construction of remote assemblages in the bootstrap
   module controller

 - adapt test code to the above changes

The aim is to eventually put the commonly useful bits -- expansion to
Flux primitives, and binding evaluation -- in the assemblage code, and
the rollout logic in the module code. An integration or extension can
then replace the module part by building on the assemblage part.

Signed-off-by: Michael Bridgen <[email protected]>
  • Loading branch information
squaremo committed Feb 21, 2022
1 parent a42cd9a commit 5e405aa
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 292 deletions.
40 changes: 35 additions & 5 deletions module/api/v1alpha1/remoteassemblage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

asmv1 "github.com/squaremo/fleeet/assemblage/api/v1alpha1"
syncapi "github.com/squaremo/fleeet/pkg/api"
)

Expand All @@ -18,11 +17,42 @@ type RemoteAssemblageSpec struct {
// +required
KubeconfigRef LocalKubeconfigReference `json:"kubeconfigRef"`

// Assemblage gives the specification for the assemblage to create
// downstream. It will be created with the same name as this
// object.
// Syncs gives the list of sync specs, each specifying a config to apply to the remote cluster.
// +optional
Syncs []RemoteSync `json:"syncs,omitempty"`
}

// SourceReference is a reference to supply to the Flux sync primitive created. Sources are shared
// amongst assemblages, rather than created per assemblage.
type SourceReference struct {
// Name gives the name of the source (which is assumed to be in the same namespace as the
// referrer).
// +required
Name string `json:"name"`
// APIVersion gives the API group and version of the source object, e.g.,
// `source.toolkit.fluxcd.io/v1beta2`
// +required
APIVersion string `json:"apiVersion"`
// Kind gives the kind of the source object, e.g., `GitRepository`
// +required
Kind string `json:"kind"`
}

type RemoteSync struct {
// Name gives a name to use for this sync, so that updates can be stable (changing the sync spec
// will update objects rather than replace them)
// +required
Name string `json:"name"`
// ControlPlaneBindings gives a list of variable bindings to evaluate when constructing the sync primitives
// +optional
ControlPlaneBindings []syncapi.Binding `json:"controlPlaneBindings,omitempty"`
// SourceRef gives a reference to the source to use in the sync primitive
// +required
SourceRef SourceReference `json:"sourceRef"`
// Package defines how the sources is to be applied; e.g., by kustomize
// +required
Assemblage asmv1.AssemblageSpec `json:"assemblage"`
// +kubebuilder:default={"kustomize": {"path": "."}}
Package *syncapi.PackageSpec `json:"package,omitempty"`
}

type LocalKubeconfigReference struct {
Expand Down
52 changes: 51 additions & 1 deletion module/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

202 changes: 92 additions & 110 deletions module/config/crd/bases/fleet.squaremo.dev_remoteassemblages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,130 +36,112 @@ spec:
spec:
description: RemoteAssemblageSpec defines the desired state of RemoteAssemblage
properties:
assemblage:
description: Assemblage gives the specification for the assemblage
to create downstream. It will be created with the same name as this
object.
kubeconfigRef:
description: KubeconfigRef refers to a secret with a kubeconfig for
the remote cluster.
properties:
syncs:
items:
description: NamedSync is used when there's a list of syncs,
so the name can be mentioned elsewhere to refer to the particular
sync. These always have their own bindings because they are
used in types that have bindings to evaluate in the target
cluster.
properties:
bindings:
description: Bindings gives a list of variable bindings
to use when evaluating the package spec in the sync
items:
description: Binding specifies how to obtain a value to
bind to a name. The name can then be mentioned elsewhere
in an object, and be replaced with the value as evaluated.
name:
description: Name gives the name of the secret containing a kubeconfig.
type: string
required:
- name
type: object
syncs:
description: Syncs gives the list of sync specs, each specifying a
config to apply to the remote cluster.
items:
properties:
controlPlaneBindings:
description: ControlPlaneBindings gives a list of variable bindings
to evaluate when constructing the sync primitives
items:
description: Binding specifies how to obtain a value to bind
to a name. The name can then be mentioned elsewhere in an
object, and be replaced with the value as evaluated.
properties:
name:
type: string
objectFieldRef:
properties:
name:
apiVersion:
description: APIVersion gives the APIVersion (<group>/<version>)
for the object's type
type: string
objectFieldRef:
properties:
apiVersion:
description: APIVersion gives the APIVersion (<group>/<version>)
for the object's type
type: string
fieldPath:
description: Path is a JSONPointer expression
for finding the value in the object identified
type: string
kind:
description: Kind gives the kind of the object's
type
type: string
name:
description: Name names the object
type: string
required:
- fieldPath
- kind
- name
type: object
value:
fieldPath:
description: Path is a JSONPointer expression for
finding the value in the object identified
type: string
kind:
description: Kind gives the kind of the object's type
type: string
name:
description: Name names the object
type: string
required:
- fieldPath
- kind
- name
type: object
type: array
name:
description: Name gives the sync a name so it can be correlated
to the status
type: string
package:
default:
kustomize:
path: .
description: Package defines how to deal with the configuration
at the source, e.g., if it's a kustomization (or YAML
files)
properties:
kustomize:
properties:
path:
default: .
description: Path gives the path within the source
to treat as the Kustomization root.
type: string
substitute:
additionalProperties:
type: string
description: Substitute gives a map of names to
values to substitute in the YAML built from the
kustomization.
type: object
type: object
type: object
source:
description: Source gives the specification for how to get
the configuration to be synced
value:
type: string
required:
- name
type: object
type: array
name:
description: Name gives a name to use for this sync, so that
updates can be stable (changing the sync spec will update
objects rather than replace them)
type: string
package:
default:
kustomize:
path: .
description: Package defines how the sources is to be applied;
e.g., by kustomize
properties:
kustomize:
properties:
git:
properties:
url:
description: URL gives the URL for the git repository
type: string
version:
description: Version gives either the revision or
tag at which to get the git repo
properties:
revision:
type: string
tag:
type: string
type: object
required:
- url
- version
path:
default: .
description: Path gives the path within the source to
treat as the Kustomization root.
type: string
substitute:
additionalProperties:
type: string
description: Substitute gives a map of names to values
to substitute in the YAML built from the kustomization.
type: object
required:
- git
type: object
type: object
sourceRef:
description: SourceRef gives a reference to the source to use
in the sync primitive
properties:
apiVersion:
description: APIVersion gives the API group and version
of the source object, e.g., `source.toolkit.fluxcd.io/v1beta2`
type: string
kind:
description: Kind gives the kind of the source object, e.g.,
`GitRepository`
type: string
name:
description: Name gives the name of the source (which is
assumed to be in the same namespace as the referrer).
type: string
required:
- apiVersion
- kind
- name
- source
type: object
type: array
required:
- syncs
type: object
kubeconfigRef:
description: KubeconfigRef refers to a secret with a kubeconfig for
the remote cluster.
properties:
name:
description: Name gives the name of the secret containing a kubeconfig.
type: string
required:
- name
type: object
required:
- name
- sourceRef
type: object
type: array
required:
- assemblage
- kubeconfigRef
type: object
status:
Expand Down
Loading

0 comments on commit 5e405aa

Please sign in to comment.