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

feat(transform): Support string joining arrays #5148

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 17 additions & 1 deletion apis/apiextensions/v1/composition_transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ const (
StringTransformTypeTrimPrefix StringTransformType = "TrimPrefix"
StringTransformTypeTrimSuffix StringTransformType = "TrimSuffix"
StringTransformTypeRegexp StringTransformType = "Regexp"
StringTransformTypeJoin StringTransformType = "Join"
)

// StringConversionType converts a string.
Expand All @@ -362,7 +363,7 @@ type StringTransform struct {

// Type of the string transform to be run.
// +optional
// +kubebuilder:validation:Enum=Format;Convert;TrimPrefix;TrimSuffix;Regexp
// +kubebuilder:validation:Enum=Format;Convert;TrimPrefix;TrimSuffix;Regexp;Join
// +kubebuilder:default=Format
Type StringTransformType `json:"type,omitempty"`

Expand All @@ -388,6 +389,10 @@ type StringTransform struct {
// Extract a match from the input using a regular expression.
// +optional
Regexp *StringTransformRegexp `json:"regexp,omitempty"`

// Join defines parameters to join a slice of values to a string.
// +optional
Join *StringTransformJoin `json:"join,omitempty"`
}

// Validate checks this StringTransform is valid.
Expand Down Expand Up @@ -417,6 +422,10 @@ func (s *StringTransform) Validate() *field.Error {
if _, err := regexp.Compile(s.Regexp.Match); err != nil {
return field.Invalid(field.NewPath("regexp", "match"), s.Regexp.Match, "invalid regexp")
}
case StringTransformTypeJoin:
if s.Join == nil {
return field.Required(field.NewPath("join"), "join transform requires a join")
}
default:
return field.Invalid(field.NewPath("type"), s.Type, "unknown string transform type")
}
Expand Down Expand Up @@ -480,6 +489,13 @@ func (c ConvertTransformFormat) IsValid() bool {
return false
}

// StringTransformJoin defines parameters to join a slice of values to a string.
type StringTransformJoin struct {
// Separator defines the character that should separate the values from each
// other in the joined string.
Separator string `json:"separator"`
}

// A ConvertTransform converts the input into a new object whose type is supplied.
type ConvertTransform struct {
// ToType is the type of the output of this transform.
Expand Down
10 changes: 10 additions & 0 deletions apis/apiextensions/v1/zz_generated.conversion.go

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

20 changes: 20 additions & 0 deletions apis/apiextensions/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ const (
StringTransformTypeTrimPrefix StringTransformType = "TrimPrefix"
StringTransformTypeTrimSuffix StringTransformType = "TrimSuffix"
StringTransformTypeRegexp StringTransformType = "Regexp"
StringTransformTypeJoin StringTransformType = "Join"
)

// StringConversionType converts a string.
Expand All @@ -364,7 +365,7 @@ type StringTransform struct {

// Type of the string transform to be run.
// +optional
// +kubebuilder:validation:Enum=Format;Convert;TrimPrefix;TrimSuffix;Regexp
// +kubebuilder:validation:Enum=Format;Convert;TrimPrefix;TrimSuffix;Regexp;Join
// +kubebuilder:default=Format
Type StringTransformType `json:"type,omitempty"`

Expand All @@ -390,6 +391,10 @@ type StringTransform struct {
// Extract a match from the input using a regular expression.
// +optional
Regexp *StringTransformRegexp `json:"regexp,omitempty"`

// Join defines parameters to join a slice of values to a string.
// +optional
Join *StringTransformJoin `json:"join,omitempty"`
}

// Validate checks this StringTransform is valid.
Expand Down Expand Up @@ -419,6 +424,10 @@ func (s *StringTransform) Validate() *field.Error {
if _, err := regexp.Compile(s.Regexp.Match); err != nil {
return field.Invalid(field.NewPath("regexp", "match"), s.Regexp.Match, "invalid regexp")
}
case StringTransformTypeJoin:
if s.Join == nil {
return field.Required(field.NewPath("join"), "join transform requires a join")
}
default:
return field.Invalid(field.NewPath("type"), s.Type, "unknown string transform type")
}
Expand Down Expand Up @@ -482,6 +491,13 @@ func (c ConvertTransformFormat) IsValid() bool {
return false
}

// StringTransformJoin defines parameters to join a slice of values to a string.
type StringTransformJoin struct {
// Separator defines the character that should separate the values from each
// other in the joined string.
Separator string `json:"separator"`
}

// A ConvertTransform converts the input into a new object whose type is supplied.
type ConvertTransform struct {
// ToType is the type of the output of this transform.
Expand Down
20 changes: 20 additions & 0 deletions apis/apiextensions/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,18 @@ spec:
string. See https://golang.org/pkg/fmt/ for
details.
type: string
join:
description: Join defines parameters to join a
slice of values to a string.
properties:
separator:
description: Separator defines the character
that should separate the values from each
other in the joined string.
type: string
required:
- separator
type: object
regexp:
description: Extract a match from the input using
a regular expression.
Expand Down Expand Up @@ -473,6 +485,7 @@ spec:
- TrimPrefix
- TrimSuffix
- Regexp
- Join
type: string
type: object
type:
Expand Down Expand Up @@ -826,6 +839,18 @@ spec:
string. See https://golang.org/pkg/fmt/ for
details.
type: string
join:
description: Join defines parameters to join
a slice of values to a string.
properties:
separator:
description: Separator defines the character
that should separate the values from each
other in the joined string.
type: string
required:
- separator
type: object
regexp:
description: Extract a match from the input
using a regular expression.
Expand Down Expand Up @@ -856,6 +881,7 @@ spec:
- TrimPrefix
- TrimSuffix
- Regexp
- Join
type: string
type: object
type:
Expand Down Expand Up @@ -1285,6 +1311,18 @@ spec:
string. See https://golang.org/pkg/fmt/ for
details.
type: string
join:
description: Join defines parameters to join
a slice of values to a string.
properties:
separator:
description: Separator defines the character
that should separate the values from each
other in the joined string.
type: string
required:
- separator
type: object
regexp:
description: Extract a match from the input
using a regular expression.
Expand Down Expand Up @@ -1315,6 +1353,7 @@ spec:
- TrimPrefix
- TrimSuffix
- Regexp
- Join
type: string
type: object
type:
Expand Down Expand Up @@ -1902,6 +1941,18 @@ spec:
string. See https://golang.org/pkg/fmt/ for
details.
type: string
join:
description: Join defines parameters to join a
slice of values to a string.
properties:
separator:
description: Separator defines the character
that should separate the values from each
other in the joined string.
type: string
required:
- separator
type: object
regexp:
description: Extract a match from the input using
a regular expression.
Expand Down Expand Up @@ -1932,6 +1983,7 @@ spec:
- TrimPrefix
- TrimSuffix
- Regexp
- Join
type: string
type: object
type:
Expand Down Expand Up @@ -2285,6 +2337,18 @@ spec:
string. See https://golang.org/pkg/fmt/ for
details.
type: string
join:
description: Join defines parameters to join
a slice of values to a string.
properties:
separator:
description: Separator defines the character
that should separate the values from each
other in the joined string.
type: string
required:
- separator
type: object
regexp:
description: Extract a match from the input
using a regular expression.
Expand Down Expand Up @@ -2315,6 +2379,7 @@ spec:
- TrimPrefix
- TrimSuffix
- Regexp
- Join
type: string
type: object
type:
Expand Down Expand Up @@ -2744,6 +2809,18 @@ spec:
string. See https://golang.org/pkg/fmt/ for
details.
type: string
join:
description: Join defines parameters to join
a slice of values to a string.
properties:
separator:
description: Separator defines the character
that should separate the values from each
other in the joined string.
type: string
required:
- separator
type: object
regexp:
description: Extract a match from the input
using a regular expression.
Expand Down Expand Up @@ -2774,6 +2851,7 @@ spec:
- TrimPrefix
- TrimSuffix
- Regexp
- Join
type: string
type: object
type:
Expand Down