Skip to content

Commit 440b029

Browse files
joelanfordEric Stroczynski
andauthored
operator-sdk/internal/generate: fix CSV path segments for multi-field structs (#4166)
Co-authored-by: Eric Stroczynski <[email protected]>
1 parent dcd8696 commit 440b029

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
entries:
2+
- description: >
3+
Fixed an issue during CSV generation that caused incorrect paths to
4+
be used in `specDescriptors` and `statusDescriptors`.
5+
kind: "bugfix"

internal/generate/clusterserviceversion/bases/definitions/ast.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ func (g generator) getMarkedChildrenOfField(root markers.FieldInfo) (map[string]
6666
}
6767
// Create a new set of path segments using the parent's segments
6868
// and add the field to the next fields to search.
69+
parentSegments := make([]string, len(field.pathSegments), len(field.pathSegments)+1)
70+
copy(parentSegments, field.pathSegments)
6971
f := &fieldInfo{
7072
FieldInfo: finfo,
71-
pathSegments: append(field.pathSegments, segment),
73+
pathSegments: append(parentSegments, segment),
7274
}
7375
fields = append(fields, f)
7476
// Marked fields get collected for the caller to parse.

internal/generate/testdata/clusterserviceversions/bases/with-ui-metadata.clusterserviceversion.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ spec:
1515
kind: Memcached
1616
name: memcacheds.cache.example.com
1717
specDescriptors:
18+
- description: List of Providers
19+
displayName: Providers
20+
path: providers
21+
- description: Foo represents the Foo provider
22+
displayName: Foo Provider
23+
path: providers[0].foo
24+
- description: CredentialsSecret is a reference to a secret containing authentication details for the Foo server
25+
displayName: Secret Containing the Credentials
26+
path: providers[0].foo.credentialsSecret
27+
x-descriptors:
28+
- urn:alm:descriptor:io.kubernetes:Secret
29+
- description: Key represents the specific key to reference from the secret
30+
displayName: Key within the secret
31+
path: providers[0].foo.credentialsSecret.key
32+
x-descriptors:
33+
- urn:alm:descriptor:com.tectonic.ui:advanced
34+
- urn:alm:descriptor:com.tectonic.ui:text
35+
- description: Name represents the name of the secret
36+
displayName: Name of the secret
37+
path: providers[0].foo.credentialsSecret.name
38+
x-descriptors:
39+
- urn:alm:descriptor:com.tectonic.ui:advanced
40+
- urn:alm:descriptor:com.tectonic.ui:text
41+
- description: Namespace represents the namespace containing the secret
42+
displayName: Namespace containing the secret
43+
path: providers[0].foo.credentialsSecret.namespace
44+
x-descriptors:
45+
- urn:alm:descriptor:com.tectonic.ui:advanced
46+
- urn:alm:descriptor:com.tectonic.ui:text
1847
- description: Size is the size of the memcached deployment
1948
displayName: Size
2049
path: size

internal/generate/testdata/clusterserviceversions/output/memcached-operator.clusterserviceversion.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ spec:
2727
kind: Memcached
2828
name: memcacheds.cache.example.com
2929
specDescriptors:
30+
- description: List of Providers
31+
displayName: Providers
32+
path: providers
33+
- description: Foo represents the Foo provider
34+
displayName: Foo Provider
35+
path: providers[0].foo
36+
- description: CredentialsSecret is a reference to a secret containing authentication details for the Foo server
37+
displayName: Secret Containing the Credentials
38+
path: providers[0].foo.credentialsSecret
39+
x-descriptors:
40+
- urn:alm:descriptor:io.kubernetes:Secret
41+
- description: Key represents the specific key to reference from the secret
42+
displayName: Key within the secret
43+
path: providers[0].foo.credentialsSecret.key
44+
x-descriptors:
45+
- urn:alm:descriptor:com.tectonic.ui:advanced
46+
- urn:alm:descriptor:com.tectonic.ui:text
47+
- description: Name represents the name of the secret
48+
displayName: Name of the secret
49+
path: providers[0].foo.credentialsSecret.name
50+
x-descriptors:
51+
- urn:alm:descriptor:com.tectonic.ui:advanced
52+
- urn:alm:descriptor:com.tectonic.ui:text
53+
- description: Namespace represents the namespace containing the secret
54+
displayName: Namespace containing the secret
55+
path: providers[0].foo.credentialsSecret.namespace
56+
x-descriptors:
57+
- urn:alm:descriptor:com.tectonic.ui:advanced
58+
- urn:alm:descriptor:com.tectonic.ui:text
3059
- description: Size is the size of the memcached deployment
3160
displayName: Size
3261
path: size

internal/generate/testdata/go/api/v1alpha1/memcached_types.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ type MemcachedSpec struct {
2323
// Size is the size of the memcached deployment
2424
// +operator-sdk:csv:customresourcedefinitions:type=spec
2525
Size int32 `json:"size"`
26+
27+
// List of Providers
28+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Providers"
29+
Providers []Provider `json:"providers,omitempty"`
30+
}
31+
32+
// Provider represents the container for a single provider
33+
type Provider struct {
34+
// Foo represents the Foo provider
35+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Foo Provider"
36+
Foo *FooProvider `json:"foo,omitempty"`
37+
}
38+
39+
// FooProvider represents integration with Foo
40+
type FooProvider struct {
41+
// CredentialsSecret is a reference to a secret containing authentication details for the Foo server
42+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Secret Containing the Credentials",xDescriptors="urn:alm:descriptor:io.kubernetes:Secret"
43+
// +kubebuilder:validation:Required
44+
CredentialsSecret *SecretRef `json:"credentialsSecret"`
45+
}
46+
47+
// SecretRef represents a reference to an item within a Secret
48+
type SecretRef struct {
49+
// Name represents the name of the secret
50+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Name of the secret",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced","urn:alm:descriptor:com.tectonic.ui:text"}
51+
Name string `json:"name"`
52+
53+
// Namespace represents the namespace containing the secret
54+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Namespace containing the secret",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced","urn:alm:descriptor:com.tectonic.ui:text"}
55+
Namespace string `json:"namespace"`
56+
57+
// Key represents the specific key to reference from the secret
58+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Key within the secret",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced","urn:alm:descriptor:com.tectonic.ui:text"}
59+
Key string `json:"key,omitempty"`
2660
}
2761

2862
// MemcachedStatus defines the observed state of Memcached

0 commit comments

Comments
 (0)