Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator-sdk/internal/generate: fix CSV path segments for multi-field structs #4166

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/fragments/fix-csv-generate-path-segments.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entries:
- description: >
Fixed an issue during CSV generation that caused incorrect paths to
be used in `specDescriptors` and `statusDescriptors`.
kind: "bugfix"
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ func (g generator) getMarkedChildrenOfField(root markers.FieldInfo) (map[string]
}
// Create a new set of path segments using the parent's segments
// and add the field to the next fields to search.
parentSegments := make([]string, len(field.pathSegments))
joelanford marked this conversation as resolved.
Show resolved Hide resolved
copy(parentSegments, field.pathSegments)
f := &fieldInfo{
FieldInfo: finfo,
pathSegments: append(field.pathSegments, segment),
pathSegments: append(parentSegments, segment),
}
fields = append(fields, f)
// Marked fields get collected for the caller to parse.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ spec:
kind: Memcached
name: memcacheds.cache.example.com
specDescriptors:
- description: List of Providers
displayName: Providers
path: providers
- description: Foo represents the Foo provider
displayName: Foo Provider
path: providers[0].foo
- description: CredentialsSecret is a reference to a secret containing authentication details for the Foo server
displayName: Secret Containing the Credentials
path: providers[0].foo.credentialsSecret
x-descriptors:
- urn:alm:descriptor:io.kubernetes:Secret
- description: Key represents the specific key to reference from the secret
displayName: Key within the secret
path: providers[0].foo.credentialsSecret.key
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- description: Name represents the name of the secret
displayName: Name of the secret
path: providers[0].foo.credentialsSecret.name
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- description: Namespace represents the namespace containing the secret
displayName: Namespace containing the secret
path: providers[0].foo.credentialsSecret.namespace
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- description: Size is the size of the memcached deployment
displayName: Size
path: size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ spec:
kind: Memcached
name: memcacheds.cache.example.com
specDescriptors:
- description: List of Providers
displayName: Providers
path: providers
- description: Foo represents the Foo provider
displayName: Foo Provider
path: providers[0].foo
- description: CredentialsSecret is a reference to a secret containing authentication details for the Foo server
displayName: Secret Containing the Credentials
path: providers[0].foo.credentialsSecret
x-descriptors:
- urn:alm:descriptor:io.kubernetes:Secret
- description: Key represents the specific key to reference from the secret
displayName: Key within the secret
path: providers[0].foo.credentialsSecret.key
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- description: Name represents the name of the secret
displayName: Name of the secret
path: providers[0].foo.credentialsSecret.name
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- description: Namespace represents the namespace containing the secret
displayName: Namespace containing the secret
path: providers[0].foo.credentialsSecret.namespace
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:text
- description: Size is the size of the memcached deployment
displayName: Size
path: size
Expand Down
34 changes: 34 additions & 0 deletions internal/generate/testdata/go/api/v1alpha1/memcached_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,40 @@ type MemcachedSpec struct {
// Size is the size of the memcached deployment
// +operator-sdk:csv:customresourcedefinitions:type=spec
Size int32 `json:"size"`

// List of Providers
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Providers"
Providers []Provider `json:"providers,omitempty"`
}

// Provider represents the container for a single provider
type Provider struct {
// Foo represents the Foo provider
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Foo Provider"
Foo *FooProvider `json:"foo,omitempty"`
}

// FooProvider represents integration with Foo
type FooProvider struct {
// CredentialsSecret is a reference to a secret containing authentication details for the Foo server
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Secret Containing the Credentials",xDescriptors="urn:alm:descriptor:io.kubernetes:Secret"
// +kubebuilder:validation:Required
CredentialsSecret *SecretRef `json:"credentialsSecret"`
}

// SecretRef represents a reference to an item within a Secret
type SecretRef struct {
// Name represents the name of the secret
// +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"}
Name string `json:"name"`

// Namespace represents the namespace containing the secret
// +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"}
Namespace string `json:"namespace"`

// Key represents the specific key to reference from the secret
// +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"}
Key string `json:"key,omitempty"`
}

// MemcachedStatus defines the observed state of Memcached
Expand Down