-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New DeploymentStrategy type for JaegerSpec.Strategy (#704)
Signed-off-by: volmedo <[email protected]>
- Loading branch information
1 parent
b986f39
commit 281ce62
Showing
26 changed files
with
177 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package v1 | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
) | ||
|
||
// DeploymentStrategy represents the possible values for deployment strategies | ||
// +k8s:openapi-gen=true | ||
type DeploymentStrategy string | ||
|
||
const ( | ||
// DeploymentStrategyDeprecatedAllInOne represents the (deprecated) 'all-in-one' deployment strategy | ||
// +k8s:openapi-gen=true | ||
DeploymentStrategyDeprecatedAllInOne DeploymentStrategy = "all-in-one" | ||
|
||
// DeploymentStrategyAllInOne represents the 'allInOne' deployment strategy (default) | ||
// +k8s:openapi-gen=true | ||
DeploymentStrategyAllInOne DeploymentStrategy = "allinone" | ||
|
||
// DeploymentStrategyStreaming represents the 'streaming' deployment strategy | ||
// +k8s:openapi-gen=true | ||
DeploymentStrategyStreaming DeploymentStrategy = "streaming" | ||
|
||
// DeploymentStrategyProduction represents the 'production' deployment strategy | ||
// +k8s:openapi-gen=true | ||
DeploymentStrategyProduction DeploymentStrategy = "production" | ||
) | ||
|
||
// UnmarshalText implements encoding.TextUnmarshaler to ensure that JSON values in the | ||
// strategy field of JSON jaeger specs are interpreted in a case-insensitive manner | ||
func (ds *DeploymentStrategy) UnmarshalText(text []byte) error { | ||
if ds == nil { | ||
return errors.New("DeploymentStrategy: UnmarshalText on nil pointer") | ||
} | ||
|
||
switch strings.ToLower(string(text)) { | ||
default: | ||
*ds = DeploymentStrategyAllInOne | ||
case string(DeploymentStrategyDeprecatedAllInOne): | ||
*ds = DeploymentStrategyDeprecatedAllInOne | ||
case string(DeploymentStrategyStreaming): | ||
*ds = DeploymentStrategyStreaming | ||
case string(DeploymentStrategyProduction): | ||
*ds = DeploymentStrategyProduction | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package v1 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUnmarshalJSON(t *testing.T) { | ||
tcs := map[string]struct { | ||
json string | ||
expected DeploymentStrategy | ||
}{ | ||
"allInOne": {json: `"allInOne"`, expected: DeploymentStrategyAllInOne}, | ||
"streaming": {json: `"streaming"`, expected: DeploymentStrategyStreaming}, | ||
"production": {json: `"production"`, expected: DeploymentStrategyProduction}, | ||
"all-in-one": {json: `"all-in-one"`, expected: DeploymentStrategyDeprecatedAllInOne}, | ||
"ALLinONE": {json: `"ALLinONE"`, expected: DeploymentStrategyAllInOne}, | ||
"StReAmInG": {json: `"StReAmInG"`, expected: DeploymentStrategyStreaming}, | ||
"Production": {json: `"Production"`, expected: DeploymentStrategyProduction}, | ||
"All-IN-One": {json: `"All-IN-One"`, expected: DeploymentStrategyDeprecatedAllInOne}, | ||
"random value": {json: `"random value"`, expected: DeploymentStrategyAllInOne}, | ||
"empty string": {json: `""`, expected: DeploymentStrategyAllInOne}, | ||
} | ||
|
||
for name, tc := range tcs { | ||
t.Run(name, func(t *testing.T) { | ||
ds := DeploymentStrategy("") | ||
err := json.Unmarshal([]byte(tc.json), &ds) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expected, ds) | ||
}) | ||
} | ||
} | ||
|
||
func TestMarshalJSON(t *testing.T) { | ||
tcs := map[string]struct { | ||
strategy DeploymentStrategy | ||
expected string | ||
}{ | ||
"allinone": {strategy: DeploymentStrategyAllInOne, expected: `"allinone"`}, | ||
"streaming": {strategy: DeploymentStrategyStreaming, expected: `"streaming"`}, | ||
"production": {strategy: DeploymentStrategyProduction, expected: `"production"`}, | ||
"all-in-one": {strategy: DeploymentStrategyDeprecatedAllInOne, expected: `"all-in-one"`}, | ||
} | ||
|
||
for name, tc := range tcs { | ||
t.Run(name, func(t *testing.T) { | ||
data, err := json.Marshal(tc.strategy) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expected, string(data)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.