-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: scaffolding for parameterset crd Signed-off-by: Steven Gettys <[email protected]> * basic paramset reconciler with existing tests passing Signed-off-by: Brian DeGeeter <[email protected]> * initial passing paramset integration test Signed-off-by: Brian DeGeeter <[email protected]> * add paramset installation test Signed-off-by: Brian DeGeeter <[email protected]> * chore: Updated docs and added some test coverage Signed-off-by: Steven Gettys <[email protected]> * chore: Added parameter for helm chart version configuration Signed-off-by: Steven Gettys <[email protected]> * docs: Fixed docs references Signed-off-by: Steven Gettys <[email protected]> Co-authored-by: Brian DeGeeter <[email protected]>
- Loading branch information
Showing
23 changed files
with
1,569 additions
and
4 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
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,114 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"gopkg.in/yaml.v3" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// SERIALIZATION NOTE: | ||
// * json tags are required for Kubernetes. Any new fields you add must have json tags for the fields to be serialized. | ||
// * yaml tags are required for Porter. Any new fields you add must have yaml tags for the fields to be serialized. | ||
|
||
// Parameter defines an element in a ParameterSet | ||
type Parameter struct { | ||
// Name is the bundle parameter name | ||
Name string `json:"name" yaml:"name"` | ||
|
||
//Source is the bundle parameter source | ||
//supported: secret, value | ||
//unsupported: file path(via configMap), env var, shell cmd | ||
Source ParameterSource `json:"source" yaml:"source"` | ||
} | ||
|
||
type ParameterSource struct { | ||
// Secret is a parameter source using a secret plugin | ||
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"` | ||
// Value is a paremeter source using plaintext value | ||
Value string `json:"value,omitempty" yaml:"value,omitempty"` | ||
} | ||
|
||
// ParameterSetSpec defines the desired state of ParameterSet | ||
type ParameterSetSpec struct { | ||
// AgentConfig is the name of an AgentConfig to use instead of the AgentConfig defined at the namespace or system level. | ||
// +optional | ||
AgentConfig *corev1.LocalObjectReference `json:"agentConfig,omitempty" yaml:"-"` | ||
|
||
// PorterConfig is the name of a PorterConfig to use instead of the PorterConfig defined at the namespace or system level. | ||
PorterConfig *corev1.LocalObjectReference `json:"porterConfig,omitempty" yaml:"-"` | ||
// | ||
// These are fields from the Porter parameter set resource. | ||
// Your goal is that someone can copy/paste a resource from Porter into the | ||
// spec and have it work. So be consistent! | ||
// | ||
|
||
// SchemaVersion is the version of the parameter set state schema. | ||
SchemaVersion string `json:"schemaVersion" yaml:"schemaVersion"` | ||
|
||
// Name is the name of the parameter set in Porter. Immutable. | ||
Name string `json:"name" yaml:"name"` | ||
|
||
// Namespace (in Porter) where the parameter set is defined. | ||
Namespace string `json:"namespace" yaml:"namespace"` | ||
// Parameters list of bundle parameters in the parameter set. | ||
Parameters []Parameter `json:"parameters" yaml:"parameters"` | ||
} | ||
|
||
func (ps ParameterSetSpec) ToPorterDocument() ([]byte, error) { | ||
b, err := yaml.Marshal(ps) | ||
return b, errors.Wrap(err, "error converting the ParameterSet spec into its Porter resource representation") | ||
} | ||
|
||
// ParameterSetStatus defines the observed state of ParameterSet | ||
type ParameterSetStatus struct { | ||
PorterResourceStatus `json:",inline"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// ParameterSet is the Schema for the parametersets API | ||
type ParameterSet struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec ParameterSetSpec `json:"spec,omitempty"` | ||
Status ParameterSetStatus `json:"status,omitempty"` | ||
} | ||
|
||
func (ps *ParameterSet) GetStatus() PorterResourceStatus { | ||
return ps.Status.PorterResourceStatus | ||
} | ||
|
||
func (ps *ParameterSet) SetStatus(value PorterResourceStatus) { | ||
ps.Status.PorterResourceStatus = value | ||
} | ||
|
||
// GetRetryLabelValue returns a value that is safe to use | ||
// as a label value and represents the retry annotation used | ||
// to trigger reconciliation. | ||
func (ps *ParameterSet) GetRetryLabelValue() string { | ||
return getRetryLabelValue(ps.Annotations) | ||
} | ||
|
||
// SetRetryAnnotation flags the resource to retry its last operation. | ||
func (ps *ParameterSet) SetRetryAnnotation(retry string) { | ||
if ps.Annotations == nil { | ||
ps.Annotations = make(map[string]string, 1) | ||
} | ||
ps.Annotations[AnnotationRetry] = retry | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// ParameterSetList contains a list of ParameterSet | ||
type ParameterSetList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ParameterSet `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ParameterSet{}, &ParameterSetList{}) | ||
} |
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,110 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
portertest "get.porter.sh/porter/pkg/test" | ||
portertests "get.porter.sh/porter/tests" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestParameterSetSpec_ToPorterDocument(t *testing.T) { | ||
wantGoldenFile := "testdata/parameter-set.yaml" | ||
type fields struct { | ||
AgentConfig *corev1.LocalObjectReference | ||
PorterConfig *corev1.LocalObjectReference | ||
SchemaVersion string | ||
Name string | ||
Namespace string | ||
Parameters []Parameter | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantFile string | ||
wantErrMsg string | ||
}{ | ||
{ | ||
name: "golden file test", | ||
fields: fields{SchemaVersion: "1.0.1", | ||
Name: "porter-test-me", | ||
Namespace: "dev", | ||
Parameters: []Parameter{ | ||
{ | ||
Name: "param1", | ||
Source: ParameterSource{Value: "test-param"}, | ||
}, | ||
{ | ||
Name: "param2", | ||
Source: ParameterSource{Secret: "test-secret"}, | ||
}, | ||
}, | ||
}, | ||
wantFile: wantGoldenFile, | ||
wantErrMsg: "", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cs := ParameterSetSpec{ | ||
AgentConfig: tt.fields.AgentConfig, | ||
PorterConfig: tt.fields.PorterConfig, | ||
SchemaVersion: tt.fields.SchemaVersion, | ||
Name: tt.fields.Name, | ||
Namespace: tt.fields.Namespace, | ||
Parameters: tt.fields.Parameters, | ||
} | ||
got, err := cs.ToPorterDocument() | ||
if tt.wantErrMsg == "" { | ||
require.NoError(t, err) | ||
portertest.CompareGoldenFile(t, tt.wantFile, string(got)) | ||
} else { | ||
portertests.RequireErrorContains(t, err, tt.wantErrMsg) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestParameterSet_SetRetryAnnotation(t *testing.T) { | ||
type fields struct { | ||
TypeMeta metav1.TypeMeta | ||
ObjectMeta metav1.ObjectMeta | ||
Spec ParameterSetSpec | ||
Status ParameterSetStatus | ||
} | ||
type args struct { | ||
retry string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
}{ | ||
{ | ||
name: "set retry 1", | ||
fields: fields{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{}, | ||
Spec: ParameterSetSpec{}, | ||
Status: ParameterSetStatus{}, | ||
}, | ||
args: args{retry: "1"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ps := &ParameterSet{ | ||
TypeMeta: tt.fields.TypeMeta, | ||
ObjectMeta: tt.fields.ObjectMeta, | ||
Spec: tt.fields.Spec, | ||
Status: tt.fields.Status, | ||
} | ||
ps.SetRetryAnnotation(tt.args.retry) | ||
assert.Equal(t, tt.args.retry, ps.Annotations[AnnotationRetry]) | ||
}) | ||
} | ||
} |
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,10 @@ | ||
schemaVersion: 1.0.1 | ||
name: porter-test-me | ||
namespace: dev | ||
parameters: | ||
- name: param1 | ||
source: | ||
value: test-param | ||
- name: param2 | ||
source: | ||
secret: test-secret |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.