Skip to content

Commit

Permalink
feat: Add patchMergeKey and patchStrategy struct tags and comments (#386
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dthomson25 committed Feb 10, 2020
1 parent 3b1d471 commit 034e7b1
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 14 deletions.
2 changes: 2 additions & 0 deletions manifests/crds/analysis-run-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spec:
kind: AnalysisRun
listKind: AnalysisRunList
plural: analysisruns
shortNames:
- ar
singular: analysisrun
scope: Namespaced
subresources: {}
Expand Down
2 changes: 2 additions & 0 deletions manifests/crds/analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ spec:
kind: AnalysisTemplate
listKind: AnalysisTemplateList
plural: analysistemplates
shortNames:
- at
singular: analysistemplate
scope: Namespaced
validation:
Expand Down
4 changes: 4 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ spec:
kind: AnalysisRun
listKind: AnalysisRunList
plural: analysisruns
shortNames:
- ar
singular: analysisrun
scope: Namespaced
subresources: {}
Expand Down Expand Up @@ -2734,6 +2736,8 @@ spec:
kind: AnalysisTemplate
listKind: AnalysisTemplateList
plural: analysistemplates
shortNames:
- at
singular: analysistemplate
scope: Namespaced
validation:
Expand Down
4 changes: 4 additions & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ spec:
kind: AnalysisRun
listKind: AnalysisRunList
plural: analysisruns
shortNames:
- ar
singular: analysisrun
scope: Namespaced
subresources: {}
Expand Down Expand Up @@ -2734,6 +2736,8 @@ spec:
kind: AnalysisTemplate
listKind: AnalysisTemplateList
plural: analysistemplates
shortNames:
- at
singular: analysistemplate
scope: Namespaced
validation:
Expand Down
25 changes: 18 additions & 7 deletions pkg/apis/rollouts/v1alpha1/analysis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// AnalysisTemplate holds the template for performing canary analysis
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:path=analysistemplates,shortName=at
type AnalysisTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -28,10 +29,14 @@ type AnalysisTemplateList struct {
// AnalysisTemplateSpec is the specification for a AnalysisTemplate resource
type AnalysisTemplateSpec struct {
// Metrics contains the list of metrics to query as part of an analysis run
Metrics []Metric `json:"metrics"`
// +patchMergeKey=name
// +patchStrategy=merge
Metrics []Metric `json:"metrics" patchStrategy:"merge" patchMergeKey:"name"`
// Args are the list of arguments to the template
// +patchMergeKey=name
// +patchStrategy=merge
// +optional
Args []Argument `json:"args,omitempty"`
Args []Argument `json:"args,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

// DurationString is a string representing a duration (e.g. 30s, 5m, 1h)
Expand Down Expand Up @@ -154,7 +159,7 @@ type JobMetric struct {
// AnalysisRun is an instantiation of an AnalysisTemplate
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:path=analysisruns
// +kubebuilder:resource:path=analysisruns, shortName=ar
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase",description="AnalysisRun status"
type AnalysisRun struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -174,10 +179,14 @@ type AnalysisRunList struct {
// AnalysisRunSpec is the spec for a AnalysisRun resource
type AnalysisRunSpec struct {
// Metrics contains the list of metrics to query as part of an analysis run
Metrics []Metric `json:"metrics"`
// +patchMergeKey=name
// +patchStrategy=merge
Metrics []Metric `json:"metrics" patchStrategy:"merge" patchMergeKey:"name"`
// Args are the list of arguments used in this run
// +optional
Args []Argument `json:"args,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Args []Argument `json:"args,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
// Terminate is used to prematurely stop the run (e.g. rollout completed and analysis is no longer desired)
Terminate bool `json:"terminate,omitempty"`
}
Expand Down Expand Up @@ -285,8 +294,10 @@ type ScopeDetail struct {
}

type WebMetric struct {
URL string `json:"url"`
Headers []WebMetricHeader `json:"headers,omitempty"`
URL string `json:"url"`
// +patchMergeKey=key
// +patchStrategy=merge
Headers []WebMetricHeader `json:"headers,omitempty" patchStrategy:"merge" patchMergeKey:"key"`
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
JSONPath string `json:"jsonPath"`
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/apis/rollouts/v1alpha1/experiment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ type Experiment struct {
// ExperimentSpec is the spec for a Experiment resource
type ExperimentSpec struct {
// Templates are a list of PodSpecs that define the ReplicaSets that should be run during an experiment.
Templates []TemplateSpec `json:"templates"`
// +patchMergeKey=name
// +patchStrategy=merge
Templates []TemplateSpec `json:"templates" patchStrategy:"merge" patchMergeKey:"name"`
// Duration the amount of time for the experiment to run as a duration string (e.g. 30s, 5m, 1h).
// If omitted, the experiment will run indefinitely, stopped either via termination, or a failed analysis run.
// +optional
Expand All @@ -42,7 +44,9 @@ type ExperimentSpec struct {
// Terminate is used to prematurely stop the experiment
Terminate bool `json:"terminate,omitempty"`
// Analyses references AnalysisTemplates to run during the experiment
Analyses []ExperimentAnalysisTemplateRef `json:"analyses,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Analyses []ExperimentAnalysisTemplateRef `json:"analyses,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

type TemplateSpec struct {
Expand Down Expand Up @@ -189,7 +193,9 @@ type ExperimentAnalysisTemplateRef struct {
TemplateName string `json:"templateName"`
// Args are the arguments that will be added to the AnalysisRuns
// +optional
Args []Argument `json:"args,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Args []Argument `json:"args,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
// RequiredForCompletion indicates that experiment should complete after analysis finishes
RequiredForCompletion bool `json:"requiredForCompletion,omitempty"`
}
Expand Down
78 changes: 78 additions & 0 deletions pkg/apis/rollouts/v1alpha1/openapi_generated.go

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

16 changes: 12 additions & 4 deletions pkg/apis/rollouts/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,16 @@ type IstioVirtualService struct {
// RolloutExperimentStep defines a template that is used to create a experiment for a step
type RolloutExperimentStep struct {
// Templates what templates that should be added to the experiment. Should be non-nil
Templates []RolloutExperimentTemplate `json:"templates"`
// +patchMergeKey=name
// +patchStrategy=merge
Templates []RolloutExperimentTemplate `json:"templates" patchStrategy:"merge" patchMergeKey:"name"`
// Duration is a duration string (e.g. 30s, 5m, 1h) that the experiment should run for
// +optional
Duration DurationString `json:"duration,omitempty"`
// Analyses reference which analysis templates to run with the experiment
Analyses []RolloutExperimentStepAnalysisTemplateRef `json:"analyses,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Analyses []RolloutExperimentStepAnalysisTemplateRef `json:"analyses,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

type RolloutExperimentStepAnalysisTemplateRef struct {
Expand All @@ -193,7 +197,9 @@ type RolloutExperimentStepAnalysisTemplateRef struct {
// TemplateName reference of the AnalysisTemplate name used by the Rollout to create the run
TemplateName string `json:"templateName"`
// Args the arguments that will be added to the AnalysisRuns
Args []AnalysisRunArgument `json:"args,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Args []AnalysisRunArgument `json:"args,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

// RolloutExperimentTemplate defines the template used to create experiments for the Rollout's experiment canary step
Expand Down Expand Up @@ -261,7 +267,9 @@ type RolloutAnalysisStep struct {
// TemplateName reference of the AnalysisTemplate name used by the Rollout to create the run
TemplateName string `json:"templateName"`
// Args the arguments that will be added to the AnalysisRuns
Args []AnalysisRunArgument `json:"args,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Args []AnalysisRunArgument `json:"args,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

// AnalysisRunArgument argument to add to analysisRun
Expand Down

0 comments on commit 034e7b1

Please sign in to comment.