Skip to content

Commit 117c50c

Browse files
committed
Update OutputResource to have LocalOutput & RemoteOutput subtypes& change to use ClusterMeta for defaults
1 parent 76792af commit 117c50c

11 files changed

+291
-101
lines changed

api/v1alpha1/addonconfig_types.go

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,42 @@ const (
9898
)
9999

100100
const (
101-
SchemaNotFound string = "SchemaNotFound"
102-
SchemaNotFoundMessage string = "Unable to find AddonConfigDefinition by name %q"
103-
InvalidSchema string = "InvalidSchema"
104-
InvalidSchemaMessage string = "Schema is invalid"
105-
SchemaUndefinedMessage string = "Schema is undefined"
106-
InvalidConfig string = "InvalidConfiguration"
107-
InvalidConfigMessage string = "Invalid configuration; see .status.fieldErrors for more information"
108-
DefaultingInternalError string = "DefaultingInternalError"
109-
DefaultingInternalErrorMessage string = "Unable to render defaults due to an internal error"
110-
TargetUndefined string = "TargetUndefined"
111-
TargetUndefinedMessage string = "No target name has been defined"
112-
TargetNotFound string = "TargetNotFound"
113-
TargetNotFoundMessage string = "No target has been found"
114-
InvalidTemplate string = "InvalidTemplate"
115-
FailedRendering string = "FailedRendering"
116-
FailedWritingRenderedTemplate string = "FailedWritingRenderedTemplate"
117-
DependencyNotFound string = "DependencyNotFound"
118-
DependencyNotFoundByNameMessage string = "Unable to find dependency by name %q"
119-
DependencyNotFoundBySelectorMessage string = "Unable to find dependency by using label selectors"
120-
DependencyUniquenessNotSatisfied string = "DependencyUniquenessNotSatisfied"
121-
DependencyUniquenessNotSatisfiedMessage string = "Multiple dependencies found while expecting a single one"
122-
DependencyTemplatingFailed string = "DependencyTemplatingFailed"
123-
DependencyNameTemplatingFailedMessage string = "Failed to template dependency name: %q"
124-
DependencySelectorTemplatingFailedMessage string = "Failed to template dependency label selector"
125-
DependencyConstraintFailed string = "DependencyConstraintFailed"
126-
DependencyIncorrectSetOfDependenciesMessage string = "incorrect set of dependency constraints"
127-
OutputResourceUndefined string = "OutputResourceUndefined"
128-
OutputResourceUndefinedMessage string = "No output resource has been defined"
129-
NameTemplatingFailed string = "NameTemplatingFailed"
130-
UpdateFailed string = "UpdateFailed"
131-
UnableToPersistRenderedTemplateMessage string = "Unable to persist the rendered template into resource %q"
101+
SchemaNotFound string = "SchemaNotFound"
102+
SchemaNotFoundMessage string = "Unable to find AddonConfigDefinition by name %q"
103+
InvalidSchema string = "InvalidSchema"
104+
InvalidSchemaMessage string = "Schema is invalid"
105+
SchemaUndefinedMessage string = "Schema is undefined"
106+
InvalidConfig string = "InvalidConfiguration"
107+
InvalidConfigMessage string = "Invalid configuration; see .status.fieldErrors for more information"
108+
DefaultingInternalError string = "DefaultingInternalError"
109+
DefaultingInternalErrorMessage string = "Unable to render defaults due to an internal error"
110+
TargetUndefined string = "TargetUndefined"
111+
TargetUndefinedMessage string = "No target name has been defined"
112+
TargetNotFound string = "TargetNotFound"
113+
TargetNotFoundMessage string = "No target has been found"
114+
InvalidTemplate string = "InvalidTemplate"
115+
FailedRendering string = "FailedRendering"
116+
FailedWritingRenderedTemplate string = "FailedWritingRenderedTemplate"
117+
DependencyNotFound string = "DependencyNotFound"
118+
DependencyNotFoundByNameMessage string = "Unable to find dependency by name %q"
119+
DependencyNotFoundBySelectorMessage string = "Unable to find dependency by using label selectors"
120+
DependencyUniquenessNotSatisfied string = "DependencyUniquenessNotSatisfied"
121+
DependencyUniquenessNotSatisfiedMessage string = "Multiple dependencies found while expecting a single one"
122+
DependencyTemplatingFailed string = "DependencyTemplatingFailed"
123+
DependencyNameTemplatingFailedMessage string = "Failed to template dependency name: %q"
124+
DependencySelectorTemplatingFailedMessage string = "Failed to template dependency label selector"
125+
DependencyConstraintFailed string = "DependencyConstraintFailed"
126+
DependencyIncorrectSetOfDependenciesMessage string = "incorrect set of dependency constraints"
127+
OutputResourceUndefined string = "OutputResourceUndefined"
128+
OutputResourceUndefinedMessage string = "No output resource has been defined"
129+
MultipleOutputResourceDefined string = "MultipleOutputResourceDefined"
130+
MultipleOutputResourceDefinedMessage string = "Multiple output resources has been defined"
131+
RemoteOutputResourceNoNamespaceDefined string = "RemoteOutputResourceNoNamespaceDefined"
132+
RemoteOutputResourceNoNamespaceDefinedMessage string = "No namespace defined for the remote output resource"
133+
134+
NameTemplatingFailed string = "NameTemplatingFailed"
135+
UpdateFailed string = "UpdateFailed"
136+
UnableToPersistRenderedTemplateMessage string = "Unable to persist the rendered template into resource %q"
132137

133138
// TODO(tvs): More detailed error messages for why they're invalid
134139
TemplateParseErrorMessage string = "Unable to parse the template"
@@ -148,11 +153,10 @@ type AddonConfig struct {
148153
Status AddonConfigStatus `json:"status,omitempty"`
149154
}
150155

151-
func (a *AddonConfig) SetOutputRef(apiVersion, kind, name string) {
156+
func (a *AddonConfig) SetOutputRef(localOutput *LocalOutput, remoteOutput *RemoteOutput) {
152157
a.Status.OutputRef = &OutputResource{
153-
APIVersion: apiVersion,
154-
Kind: kind,
155-
Name: name,
158+
LocalOutput: localOutput,
159+
RemoteOutput: remoteOutput,
156160
}
157161
}
158162

api/v1alpha1/common_types.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,29 @@ type Target struct {
5656
//Constraints []map[string]string `json:"constraints,omitempty" protobuf:"bytes,5,opt,name=constraints"`
5757
}
5858

59-
// OutputResource defines an output resource target resource version, kind and name to use when persisting resulting config into a resource.
59+
// OutputResource defines a local or remote output resource
6060
type OutputResource struct {
61+
// LocalOutput used when the OutputResource for persisting resulting config should reside within the local cluster.
62+
LocalOutput *LocalOutput `json:"localOutput,omitempty" protobuf:"bytes,1,opt,name=localOutput"`
63+
64+
// RemoteOutput used when the OutputResource for persisting resulting config should reside within the remote cluster.
65+
RemoteOutput *RemoteOutput `json:"remoteOutput,omitempty" protobuf:"bytes,1,opt,name=remoteOutput"`
66+
}
67+
68+
// LocalOutput defines the local output resource version, kind and name to use when persisting resulting config into a resource within the local cluster.
69+
type LocalOutput struct {
70+
// API version of the output resource referent.
71+
APIVersion string `json:"apiVersion" protobuf:"bytes,1,opt,name=apiVersion"`
72+
73+
// Kind of the output resource referent.
74+
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
75+
76+
// Name of the output resource referent.
77+
Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"`
78+
}
79+
80+
// RemoteOutput defines the remote output resource version, kind, name and namespace to use when persisting resulting config into a resource within the remote cluster.
81+
type RemoteOutput struct {
6182
// API version of the output resource referent.
6283
APIVersion string `json:"apiVersion" protobuf:"bytes,1,opt,name=apiVersion"`
6384

@@ -66,6 +87,9 @@ type OutputResource struct {
6687

6788
// Name of the output resource referent.
6889
Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"`
90+
91+
// Namespace of the output resource referent.
92+
Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"`
6993
}
7094

7195
// DependencyConstraint defines type for the dependency constraint object

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/addon.tvs.io_addonconfigdefinitions.yaml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,43 @@ spec:
138138
template. Only supports `Secret` and `ConfigMap` TODO(tvs): Figure
139139
out how to include metadata on the resource'
140140
properties:
141-
apiVersion:
142-
description: API version of the output resource referent.
143-
type: string
144-
kind:
145-
description: Kind of the output resource referent.
146-
type: string
147-
name:
148-
description: Name of the output resource referent.
149-
type: string
150-
required:
151-
- apiVersion
152-
- kind
141+
localOutput:
142+
description: LocalOutput used when the OutputResource for persisting
143+
resulting config should reside within the local cluster.
144+
properties:
145+
apiVersion:
146+
description: API version of the output resource referent.
147+
type: string
148+
kind:
149+
description: Kind of the output resource referent.
150+
type: string
151+
name:
152+
description: Name of the output resource referent.
153+
type: string
154+
required:
155+
- apiVersion
156+
- kind
157+
type: object
158+
remoteOutput:
159+
description: RemoteOutput used when the OutputResource for persisting
160+
resulting config should reside within the remote cluster.
161+
properties:
162+
apiVersion:
163+
description: API version of the output resource referent.
164+
type: string
165+
kind:
166+
description: Kind of the output resource referent.
167+
type: string
168+
name:
169+
description: Name of the output resource referent.
170+
type: string
171+
namespace:
172+
description: Namespace of the output resource referent.
173+
type: string
174+
required:
175+
- apiVersion
176+
- kind
177+
type: object
153178
type: object
154179
schema:
155180
description: Schema describes the schema used for validation, pruning,

config/crd/bases/addon.tvs.io_addonconfigs.yaml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,43 @@ spec:
139139
outputRef:
140140
description: OutputRef describes where the rendered template is persisted.
141141
properties:
142-
apiVersion:
143-
description: API version of the output resource referent.
144-
type: string
145-
kind:
146-
description: Kind of the output resource referent.
147-
type: string
148-
name:
149-
description: Name of the output resource referent.
150-
type: string
151-
required:
152-
- apiVersion
153-
- kind
142+
localOutput:
143+
description: LocalOutput used when the OutputResource for persisting
144+
resulting config should reside within the local cluster.
145+
properties:
146+
apiVersion:
147+
description: API version of the output resource referent.
148+
type: string
149+
kind:
150+
description: Kind of the output resource referent.
151+
type: string
152+
name:
153+
description: Name of the output resource referent.
154+
type: string
155+
required:
156+
- apiVersion
157+
- kind
158+
type: object
159+
remoteOutput:
160+
description: RemoteOutput used when the OutputResource for persisting
161+
resulting config should reside within the remote cluster.
162+
properties:
163+
apiVersion:
164+
description: API version of the output resource referent.
165+
type: string
166+
kind:
167+
description: Kind of the output resource referent.
168+
type: string
169+
name:
170+
description: Name of the output resource referent.
171+
type: string
172+
namespace:
173+
description: Namespace of the output resource referent.
174+
type: string
175+
required:
176+
- apiVersion
177+
- kind
178+
type: object
154179
type: object
155180
type: object
156181
type: object

config/samples/addon_v1alpha1_addonconfigdefinition_antrea.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ kind: AddonConfigDefinition
33
metadata:
44
name: antrea
55
spec:
6+
dependencies:
7+
- name: cluster
8+
target:
9+
apiVersion: cluster.x-k8s.io/v1beta1
10+
kind: Cluster
11+
name: "{{.Default.ClusterMeta.name}}"
612
schema:
713
openAPIV3Schema:
814
type: object
@@ -47,14 +53,15 @@ spec:
4753
type: boolean
4854
default: false
4955
outputResource:
50-
apiVersion: v1
51-
kind: Secret
52-
name: "{{.Default.Cluster.metadata.name}}-antrea-values"
56+
localOutput:
57+
apiVersion: v1
58+
kind: Secret
59+
name: "{{.Default.ClusterMeta.name}}-antrea-values"
5360
template: |
5461
infraProvider: {{.Default.Infrastructure}}
5562
antrea:
5663
config:
57-
{{ if and (not (eq (index .Default.Cluster.spec "clusterNetwork") nil)) (not (eq (index .Default.Cluster.spec.clusterNetwork "services") nil)) (not (eq (index .Default.Cluster.spec.clusterNetwork.services "cidrBlocks") nil)) }}serviceCIDR:{{index .Default.Cluster "spec" "clusterNetwork" "services" "cidrBlocks" 0}}{{- end }}
64+
{{ if and (not (eq (index .Dependencies.cluster.spec "clusterNetwork") nil)) (not (eq (index .Dependencies.cluster.spec.clusterNetwork "services") nil)) (not (eq (index .Dependencies.cluster.spec.clusterNetwork.services "cidrBlocks") nil)) }}serviceCIDR:{{index .Dependencies.cluster "spec" "clusterNetwork" "services" "cidrBlocks" 0}}{{- end }}
5865
trafficEncapMode: {{.Values.trafficEncapMode}}
5966
noSNAT: {{.Values.noSNAT}}
6067
disableUdpTunnelOffload: {{.Values.disableUdpTunnelOffload}}

config/samples/addon_v1alpha1_addonconfigdefinition_antrea_changed.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ spec:
5151
required:
5252
- foo
5353
outputResource:
54-
apiVersion: v1
55-
kind: Secret
56-
name: "{{.Default.Cluster.metadata.name}}-antrea-changed-values"
54+
localOutput:
55+
apiVersion: v1
56+
kind: Secret
57+
name: "{{.Default.ClusterMeta.name}}-antrea-changed-values"
5758
template: |
5859
infraProvider: {{.Default.Infrastructure}}
5960
antrea:

config/samples/addon_v1alpha1_addonconfigdefinition_sample.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
kind: Secret
1616
selector:
1717
matchLabels:
18-
cluster.x-k8s.io/cluster-name: "{{.Default.Cluster.metadata.name}}"
18+
cluster.x-k8s.io/cluster-name: "{{.Default.ClusterMeta.name}}"
1919
matchExpressions:
2020
- { key: foo, operator: In, values: ["{{.Default.Infrastructure}}"] }
2121
constraints:
@@ -45,9 +45,10 @@ spec:
4545
required:
4646
- foo
4747
outputResource:
48-
apiVersion: v1
49-
kind: ConfigMap
50-
name: "{{.Default.Cluster.metadata.name}}-sample-values"
48+
localOutput:
49+
apiVersion: v1
50+
kind: ConfigMap
51+
name: "{{.Default.ClusterMeta.name}}-sample-values"
5152
template: |
5253
config.yml: |
5354
infraProvider: {{.Default.Infrastructure}}

0 commit comments

Comments
 (0)