Skip to content

Commit

Permalink
TopologyMutation: Implement external patches
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Jun 13, 2022
1 parent 9bb071e commit 39d5a32
Show file tree
Hide file tree
Showing 33 changed files with 1,127 additions and 184 deletions.
20 changes: 19 additions & 1 deletion api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,13 @@ type ClusterClassPatch struct {

// Definitions define the patches inline.
// Note: Patches will be applied in the order of the array.
Definitions []PatchDefinition `json:"definitions"`
// +optional
Definitions []PatchDefinition `json:"definitions,omitempty"`

// External defines an external patch.
// FIXME(sbueringer): internal or external only => validate
// +optional
External *ExternalPatchDefinition `json:"external,omitempty"`
}

// PatchDefinition defines a patch which is applied to customize the referenced templates.
Expand Down Expand Up @@ -441,6 +447,18 @@ type JSONPatchValue struct {
Template *string `json:"template,omitempty"`
}

// ExternalPatchDefinition defines an external patch.
type ExternalPatchDefinition struct {
// GenerateExtension references an extension which is called to generate patches.
// FIXME(sbueringer): Q: Fine that GenerateExtension is optional as well?
// +optional
GenerateExtension *string `json:"generateExtension,omitempty"`

// GenerateExtension references an extension which is called to validate the topology.
// +optional
ValidateExtension *string `json:"validateExtension,omitempty"`
}

// LocalObjectTemplate defines a template for a topology Class.
type LocalObjectTemplate struct {
// Ref is a required reference to a custom resource
Expand Down
30 changes: 30 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

38 changes: 36 additions & 2 deletions api/v1beta1/zz_generated.openapi.go

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

15 changes: 14 additions & 1 deletion config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,24 @@ spec:
will be disabled. If EnabledIf is not set, the patch will
be enabled per default.
type: string
external:
description: 'External defines an external patch. FIXME(sbueringer):
internal or external only => validate'
properties:
generateExtension:
description: 'GenerateExtension references an extension
which is called to generate patches. FIXME(sbueringer):
Q: Fine that GenerateExtension is optional as well?'
type: string
validateExtension:
description: GenerateExtension references an extension which
is called to validate the topology.
type: string
type: object
name:
description: Name of the patch.
type: string
required:
- definitions
- name
type: object
type: array
Expand Down
4 changes: 4 additions & 0 deletions controllers/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
clustertopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/cluster"
machinedeploymenttopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machinedeployment"
machinesettopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machineset"
runtimeclient "sigs.k8s.io/cluster-api/internal/runtime/client"
)

// Following types provides access to reconcilers implemented in internal/controllers, thus
Expand Down Expand Up @@ -133,6 +134,8 @@ type ClusterTopologyReconciler struct {
// race conditions caused by an outdated cache.
APIReader client.Reader

RuntimeClient runtimeclient.Client

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string

Expand All @@ -146,6 +149,7 @@ func (r *ClusterTopologyReconciler) SetupWithManager(ctx context.Context, mgr ct
Client: r.Client,
APIReader: r.APIReader,
UnstructuredCachingClient: r.UnstructuredCachingClient,
RuntimeClient: r.RuntimeClient,
WatchFilterValue: r.WatchFilterValue,
}).SetupWithManager(ctx, mgr, options)
}
Expand Down
5 changes: 3 additions & 2 deletions exp/runtime/hooks/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ type RetryResponseObject interface {

// CommonResponse is the data structure common to all response types.
type CommonResponse struct {
// Status of the call. One of "Success" or "Failure".
// Status of the call.
// One of: "Success" or "Failure".
Status ResponseStatus `json:"status"`

// A human-readable description of the status of the call.
Message string `json:"message"`
Message string `json:"message,omitempty"`
}

// SetMessage sets the message field for the CommonResponse.
Expand Down
2 changes: 1 addition & 1 deletion exp/runtime/hooks/api/v1alpha1/topologymutation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ type HolderReference struct {
}

// ValidateTopology validates the Cluster topology after all patches have been applied.
func ValidateTopology(*GeneratePatchesRequest, *GeneratePatchesResponse) {}
func ValidateTopology(*ValidateTopologyRequest, *ValidateTopologyResponse) {}

func init() {
catalogBuilder.RegisterHook(GeneratePatches, &runtimecatalog.HookMeta{
Expand Down
Loading

0 comments on commit 39d5a32

Please sign in to comment.