Skip to content

Commit

Permalink
input.parameters
Browse files Browse the repository at this point in the history
* fix plugin generator nil panic

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* input.parameters

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
crenshaw-dev authored and binboum committed May 26, 2023
1 parent f8bc0d1 commit 264fcd4
Show file tree
Hide file tree
Showing 14 changed files with 1,246 additions and 982 deletions.
4 changes: 2 additions & 2 deletions applicationset/generators/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func (g *PluginGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.App
return nil, err
}

list, err := pluginClient.List(ctx, providerConfig.InputParameters)
list, err := pluginClient.List(ctx, providerConfig.Input.Parameters)
if err != nil {
return nil, fmt.Errorf("error listing params: %w", err)
}

res, err := g.generateParams(appSetGenerator, applicationSetInfo, list.OutputParameters, appSetGenerator.Plugin.InputParameters, applicationSetInfo.Spec.GoTemplate)
res, err := g.generateParams(appSetGenerator, applicationSetInfo, list.OutputParameters, appSetGenerator.Plugin.Input.Parameters, applicationSetInfo.Spec.GoTemplate)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions applicationset/generators/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,11 @@ func TestPluginGenerateParams(t *testing.T) {

generatorConfig := argoprojiov1alpha1.ApplicationSetGenerator{
Plugin: &argoprojiov1alpha1.PluginGenerator{
ConfigMapRef: argoprojiov1alpha1.PluginConfigMapRef{Name: testCase.configmap.Name},
InputParameters: testCase.inputParameters,
Values: testCase.values,
ConfigMapRef: argoprojiov1alpha1.PluginConfigMapRef{Name: testCase.configmap.Name},
Input: argoprojiov1alpha1.PluginInput{
Parameters: testCase.inputParameters,
},
Values: testCase.values,
},
}

Expand Down
14 changes: 8 additions & 6 deletions applicationset/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,14 @@ func TestRenderGeneratorParams_does_not_panic(t *testing.T) {
ConfigMapRef: argoappsv1.PluginConfigMapRef{
Name: "cm-plugin",
},
InputParameters: map[string]apiextensionsv1.JSON{
"branch": {
Raw: []byte(`"{{.branch}}"`),
},
"repo": {
Raw: []byte(`"argo-test"`),
Input: argoappsv1.PluginInput{
Parameters: map[string]apiextensionsv1.JSON{
"branch": {
Raw: []byte(`"{{.branch}}"`),
},
"repo": {
Raw: []byte(`"argo-test"`),
},
},
},
},
Expand Down
20 changes: 14 additions & 6 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7318,12 +7318,8 @@
"configMapRef": {
"$ref": "#/definitions/v1alpha1PluginConfigMapRef"
},
"inputParameters": {
"description": "InputParameters contains the information to pass to the plugin. It is a map. The keys must be strings, and the\nvalues can be any type.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/v1JSON"
}
"input": {
"$ref": "#/definitions/v1alpha1PluginInput"
},
"requeueAfterSeconds": {
"description": "RequeueAfterSeconds determines how long the ApplicationSet controller will wait before reconciling the ApplicationSet again.",
Expand All @@ -7342,6 +7338,18 @@
}
}
},
"v1alpha1PluginInput": {
"type": "object",
"properties": {
"parameters": {
"description": "Parameters contains the information to pass to the plugin. It is a map. The keys must be strings, and the\nvalues can be any type.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/v1JSON"
}
}
}
},
"v1alpha1ProjectRole": {
"type": "object",
"title": "ProjectRole represents a role that has access to a project",
Expand Down
19 changes: 10 additions & 9 deletions docs/operator-manual/applicationset/Generators-Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ spec:
# Specify the configMap where the plugin configuration is located.
configMapRef:
name: my-plugin
# You can pass arbitrary parameters to the plugin. `inputParameters` is a map, but values may be any type.
# You can pass arbitrary parameters to the plugin. `input.parameters` is a map, but values may be any type.
# These parameters will also be available on the generator's output under the `inputParameters` key.
inputParameters:
key1: "value1"
key2: "value2"
list: ["list", "of", "values"]
boolean: true
map:
input:
parameters:
key1: "value1"
key2: "value2"
key3: "value3"
list: ["list", "of", "values"]
boolean: true
map:
key1: "value1"
key2: "value2"
key3: "value3"

# You can also attach arbitrary values to the generator's output under the `values` key. These values will be
# available in templates under the `values` key.
Expand All @@ -57,7 +58,7 @@ spec:
```
* `configMapRef.name`: A `ConfigMap` name containing the plugin configuration to use for RPC call.
* `inputParameters`: InputParameters included in the RPC call to the plugin. (Optional)
* `input.parameters`: Input parameters included in the RPC call to the plugin. (Optional)

!!! note
The concept of the plugin should not undermine the spirit of GitOps by externalizing data outside of Git. The goal is to be complementary in specific contexts.
Expand Down
27 changes: 18 additions & 9 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8488,9 +8488,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -12808,9 +12811,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -15085,9 +15091,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down
27 changes: 18 additions & 9 deletions manifests/crds/applicationset-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4128,9 +4128,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -8448,9 +8451,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -10725,9 +10731,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down
27 changes: 18 additions & 9 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8488,9 +8488,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -12808,9 +12811,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -15085,9 +15091,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down
27 changes: 18 additions & 9 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8488,9 +8488,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -12808,9 +12811,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down Expand Up @@ -15085,9 +15091,12 @@ spec:
required:
- name
type: object
inputParameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
input:
properties:
parameters:
additionalProperties:
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
requeueAfterSeconds:
format: int64
Expand Down
28 changes: 17 additions & 11 deletions pkg/apis/application/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ type ApplicationSetGenerator struct {
SCMProvider *SCMProviderGenerator `json:"scmProvider,omitempty" protobuf:"bytes,4,name=scmProvider"`
ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty" protobuf:"bytes,5,name=clusterDecisionResource"`
PullRequest *PullRequestGenerator `json:"pullRequest,omitempty" protobuf:"bytes,6,name=pullRequest"`
Plugin *PluginGenerator `json:"plugin,omitempty" protobuf:"bytes,7,name=plugin"`
Matrix *MatrixGenerator `json:"matrix,omitempty" protobuf:"bytes,8,name=matrix"`
Merge *MergeGenerator `json:"merge,omitempty" protobuf:"bytes,9,name=merge"`
Matrix *MatrixGenerator `json:"matrix,omitempty" protobuf:"bytes,7,name=matrix"`
Merge *MergeGenerator `json:"merge,omitempty" protobuf:"bytes,8,name=merge"`

// Selector allows to post-filter all generator.
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,10,name=selector"`
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,9,name=selector"`

Plugin *PluginGenerator `json:"plugin,omitempty" protobuf:"bytes,10,name=plugin"`
}

// ApplicationSetNestedGenerator represents a generator nested within a combination-type generator (MatrixGenerator or
Expand All @@ -135,16 +136,17 @@ type ApplicationSetNestedGenerator struct {
SCMProvider *SCMProviderGenerator `json:"scmProvider,omitempty" protobuf:"bytes,4,name=scmProvider"`
ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty" protobuf:"bytes,5,name=clusterDecisionResource"`
PullRequest *PullRequestGenerator `json:"pullRequest,omitempty" protobuf:"bytes,6,name=pullRequest"`
Plugin *PluginGenerator `json:"plugin,omitempty" protobuf:"bytes,7,name=plugin"`

// Matrix should have the form of NestedMatrixGenerator
Matrix *apiextensionsv1.JSON `json:"matrix,omitempty" protobuf:"bytes,8,name=matrix"`
Matrix *apiextensionsv1.JSON `json:"matrix,omitempty" protobuf:"bytes,7,name=matrix"`

// Merge should have the form of NestedMergeGenerator
Merge *apiextensionsv1.JSON `json:"merge,omitempty" protobuf:"bytes,9,name=merge"`
Merge *apiextensionsv1.JSON `json:"merge,omitempty" protobuf:"bytes,8,name=merge"`

// Selector allows to post-filter all generator.
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,10,name=selector"`
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,9,name=selector"`

Plugin *PluginGenerator `json:"plugin,omitempty" protobuf:"bytes,10,name=plugin"`
}

type ApplicationSetNestedGenerators []ApplicationSetNestedGenerator
Expand Down Expand Up @@ -540,12 +542,16 @@ type PluginConfigMapRef struct {
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
}

type PluginInput struct {
// Parameters contains the information to pass to the plugin. It is a map. The keys must be strings, and the
// values can be any type.
Parameters map[string]apiextensionsv1.JSON `json:"parameters,omitempty" protobuf:"bytes,1,name=parameters"`
}

// PluginGenerator defines connection info specific to Plugin.
type PluginGenerator struct {
ConfigMapRef PluginConfigMapRef `json:"configMapRef" protobuf:"bytes,1,name=configMapRef"`
// InputParameters contains the information to pass to the plugin. It is a map. The keys must be strings, and the
// values can be any type.
InputParameters map[string]apiextensionsv1.JSON `json:"inputParameters,omitempty" protobuf:"bytes,2,name=inputParameters"`
Input PluginInput `json:"input,omitempty" protobuf:"bytes,2,name=input"`
// RequeueAfterSeconds determines how long the ApplicationSet controller will wait before reconciling the ApplicationSet again.
RequeueAfterSeconds *int64 `json:"requeueAfterSeconds,omitempty" protobuf:"varint,3,opt,name=requeueAfterSeconds"`
Template ApplicationSetTemplate `json:"template,omitempty" protobuf:"bytes,4,name=template"`
Expand Down
Loading

0 comments on commit 264fcd4

Please sign in to comment.