-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Büringer [email protected] Co-authored-by: fabriziopandini <[email protected]>
- Loading branch information
1 parent
de11b77
commit bf6dccd
Showing
12 changed files
with
2,159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
controllers/topology/internal/extensions/patches/api/interface.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package api contains the API definition for the patch engine. | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
) | ||
|
||
// Generator defines a component that can generate patches for ClusterClass templates. | ||
// NOTE: We are introducing this interface as a decoupling layer between the patch engine and the concrete components | ||
// responsible for generating patches, because we aim to provide support for external patches in a future iteration. | ||
// We also assume that this interface and all the related types will be moved in a separated (versioned) package thus | ||
// providing a versioned contract between Cluster API and the components implementing external patch extensions. | ||
type Generator interface { | ||
// Generate generates patches for templates. | ||
// GenerateRequest contains templates and the corresponding variables. | ||
// GenerateResponse contains the patches which should be applied to the templates of the GenerateRequest. | ||
Generate(ctx context.Context, request *GenerateRequest) (*GenerateResponse, error) | ||
} | ||
|
||
// GenerateRequest defines the input for a Generate request. | ||
type GenerateRequest struct { | ||
// Variables is a name/value map containing variables. | ||
Variables map[string]apiextensionsv1.JSON | ||
|
||
// Items contains the list of templates to generate patches for. | ||
Items []*GenerateRequestTemplate | ||
} | ||
|
||
// GenerateRequestTemplate defines one of the ClusterClass templates to generate patches for. | ||
type GenerateRequestTemplate struct { | ||
// TemplateID identifies a template to generate patches for; | ||
// the same TemplateID must be used when specifying to which template a generated patch should be applied to. | ||
TemplateID TemplateID | ||
|
||
// Variables is a name/value map containing variables specifically for the current template. | ||
// For example some builtin variables like MachineDeployment replicas and version are context-sensitive | ||
// and thus are only added to templates for MachineDeployments and with values which correspond to the | ||
// current MachineDeployment. | ||
Variables map[string]apiextensionsv1.JSON | ||
|
||
// Template contains the template. | ||
Template apiextensionsv1.JSON | ||
} | ||
|
||
// TemplateID identifies one of the ClusterClass templates to generate patches for; | ||
// the same TemplateID must be used when specifying where a generated patch should apply to. | ||
type TemplateID struct { | ||
// APIVersion of the current template. | ||
APIVersion string | ||
|
||
// Kind of the current template. | ||
Kind string | ||
|
||
// TargetType defines where the template is used. | ||
TargetType TargetType | ||
|
||
// MachineDeployment specifies the MachineDeployment in which the template is used. | ||
// This field is only set if the template is used in the context of a MachineDeployment. | ||
MachineDeployment MachineDeploymentID | ||
} | ||
|
||
// MachineDeploymentID specifies the MachineDeployment in which the template is used. | ||
type MachineDeploymentID struct { | ||
// TopologyName is the name of the MachineDeploymentTopology. | ||
TopologyName string | ||
|
||
// Class is the name of the MachineDeploymentClass. | ||
Class string | ||
} | ||
|
||
// TargetType define the type for target types enum. | ||
type TargetType int32 | ||
|
||
const ( | ||
// InfrastructureClusterTemplateTargetType identifies a template for the InfrastructureCluster object. | ||
InfrastructureClusterTemplateTargetType TargetType = iota | ||
|
||
// ControlPlaneTemplateTargetType identifies a template for the ControlPlane object. | ||
ControlPlaneTemplateTargetType | ||
|
||
// ControlPlaneInfrastructureMachineTemplateTargetType identifies a template for the InfrastructureMachines to be used for the ControlPlane object. | ||
ControlPlaneInfrastructureMachineTemplateTargetType | ||
|
||
// MachineDeploymentBootstrapConfigTemplateTargetType identifies a template for the BootstrapConfig to be used for a MachineDeployment object. | ||
MachineDeploymentBootstrapConfigTemplateTargetType | ||
|
||
// MachineDeploymentInfrastructureMachineTemplateTargetType identifies a template for the InfrastructureMachines to be used for a MachineDeployment object. | ||
MachineDeploymentInfrastructureMachineTemplateTargetType | ||
) | ||
|
||
var ( | ||
// TargetTypeToName maps from a TargetType to its string representation. | ||
TargetTypeToName = map[TargetType]string{ | ||
InfrastructureClusterTemplateTargetType: "InfrastructureClusterTemplate", | ||
ControlPlaneTemplateTargetType: "ControlPlaneTemplate", | ||
ControlPlaneInfrastructureMachineTemplateTargetType: "ControlPlane/InfrastructureMachineTemplate", | ||
MachineDeploymentBootstrapConfigTemplateTargetType: "MachineDeployment/BootstrapConfigTemplate", | ||
MachineDeploymentInfrastructureMachineTemplateTargetType: "MachineDeployment/InfrastructureMachineTemplate", | ||
} | ||
) | ||
|
||
// PatchType define the type for patch types enum. | ||
type PatchType int32 | ||
|
||
const ( | ||
// JSONPatchType identifies a https://datatracker.ietf.org/doc/html/rfc6902 json patch. | ||
JSONPatchType PatchType = 0 | ||
|
||
// JSONMergePatchType identifies a https://datatracker.ietf.org/doc/html/rfc7386 json merge patch. | ||
JSONMergePatchType PatchType = 1 | ||
) | ||
|
||
// GenerateResponse defines the response of a Generate request. | ||
// NOTE: Patches defined in GenerateResponse will be applied to the original GenerateRequest object, thus | ||
// adding changes on templates across all the subsequent Generate calls. | ||
type GenerateResponse struct { | ||
// Items contains the list of generated patches. | ||
Items []GenerateResponsePatch | ||
} | ||
|
||
// GenerateResponsePatch defines a Patch targeting a specific GenerateRequestTemplate. | ||
type GenerateResponsePatch struct { | ||
// TemplateID identifies the template the patch should apply to. | ||
TemplateID TemplateID | ||
|
||
// Patch contains the patch. | ||
Patch apiextensionsv1.JSON | ||
|
||
// Patch defines the type of the JSON patch. | ||
PatchType PatchType | ||
} |
Oops, something went wrong.