Skip to content

Commit

Permalink
operator-sdk/internal/generate: fix CSV path segments for multi-field…
Browse files Browse the repository at this point in the history
… structs (operator-framework#4166)

Co-authored-by: Eric Stroczynski <estroczy@redhat.com>
Signed-off-by: reinvantveer <rein.van.t.veer@geodan.nl>
  • Loading branch information
2 people authored and reinvantveer committed Feb 5, 2021
1 parent 8f53496 commit b485b87
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
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), len(field.pathSegments)+1)
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

0 comments on commit b485b87

Please sign in to comment.