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

Sanity check if the image name has a colon #922

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/resource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@ func (cluster Cluster) IsLoggingAPIEnabled() bool {
if cluster.Spec().CockroachDBVersion != "" {
version = cluster.Spec().CockroachDBVersion
} else if cluster.Spec().Image != nil && cluster.Spec().Image.Name != "" {
version = strings.Split(cluster.Spec().Image.Name, ":")[1]
split_result := strings.Split(cluster.Spec().Image.Name, ":")
if len(split_result) > 1 {
version = split_result[1]
} else {
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a log line here or something? I'm just thinking that if this condition is hit (no semi-colon in the image name), how would the end user know?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tried to add the log line before, but it seems that a parameter that defines the logger needs to be passed to this function. However, this parameter is currently not available in this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be sufficient to add an else branch here that lets the user know that logging is not enabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have added it in the latest commit.

}
} else {
return false
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/resource/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,29 @@ func TestClusterTLSSecrets(t *testing.T) {
})
}
}

func TestClusterImageName(t *testing.T) {
var (
testCluster = "test-cluster"
testNS = "test-ns"
customImageName = "custom-image-name"
)
clusterBuilder := testutil.NewBuilder(testCluster).Namespaced(testNS)
for _, tt := range []struct {
name string
cluster *resource.Cluster
imageName string
}{
{
name: "verify image name without colon",
cluster: clusterBuilder.WithImage(customImageName).Cluster(),
imageName: customImageName,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're missing the case where logging is enabled here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I have added it.

} {
t.Run(tt.name, func(t *testing.T) {
if tt.cluster.IsLoggingAPIEnabled() {
assert.Fail(t, "LoggingAPI should be disabled when image name does not contain colon")
}
})
}
}