Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
63 changes: 32 additions & 31 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linters:
- copyloopvar
- decorder
- dogsled
# - dupl # temporarily disabled - has 2 issues
- dupl
- dupword
- durationcheck
- errchkjson
Expand All @@ -32,7 +32,7 @@ linters:
- gomoddirectives
- gomodguard
- goprintffuncname
# - gosmopolitan # temporarily disabled - has 2 issues
- gosmopolitan
- govet
- grouper
- iface
Expand All @@ -48,7 +48,7 @@ linters:
- nilerr
- nilnesserr
- noctx
# - nolintlint # temporarily disabled - has 4 issues
- nolintlint
- nosprintfhostport
- predeclared
- promlinter
Expand All @@ -60,6 +60,7 @@ linters:
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagliatelle
- testableexamples
- tparallel
Expand All @@ -77,7 +78,6 @@ linters:
# We SHOULD try and evaluate each of them eventually and either fix their reports
# or comment here on why we decided to not listen to them.
- errcheck # temporarily disabled - has 11 issues
- staticcheck # temporarily disabled - has 7 issues
- cyclop
- depguard
- err113
Expand Down Expand Up @@ -109,6 +109,32 @@ linters:
- thelper
- varnamelen
- wrapcheck
settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 250
dupl:
threshold: 400
govet:
settings:
printf:
funcs:
- (github.com/kudobuilder/kuttl/internal/utils.Logger).Logf
- (github.com/kudobuilder/kuttl/internal/utils.TestLogger).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Wrapf
# TODO: fix the `context` usage in step package and enable these linters.
usetesting:
context-background: false
context-todo: false
exclusions:
paths:
- hack
- dist
- keps
- kind-*

formatters:
enable:
Expand All @@ -117,31 +143,6 @@ formatters:
settings:
goimports:
# Don't use 'github.com/kudobuilder/kuttl', it'll result in unreliable output!
local-prefixes: github.com/kudobuilder
local-prefixes:
- github.com/kudobuilder

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 250
dupl:
threshold: 400
govet:
settings:
printf:
funcs:
- (github.com/kudobuilder/kuttl/internal/utils.Logger).Logf
- (github.com/kudobuilder/kuttl/internal/utils.TestLogger).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Wrapf
# TODO: fix the `context` usage in step package and enable these linters.
usetesting:
context-background: false
context-todo: false
issues:
exclude-dirs:
- hack
- dist
- keps
- kind-*
8 changes: 4 additions & 4 deletions internal/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func Kubeconfig(cfg *rest.Config, w io.Writer) error {
Name: "cluster",
Cluster: appsv1.Cluster{
Server: cfg.Host,
CertificateAuthorityData: cfg.TLSClientConfig.CAData,
InsecureSkipTLSVerify: cfg.TLSClientConfig.Insecure,
CertificateAuthorityData: cfg.CAData,
InsecureSkipTLSVerify: cfg.Insecure,
},
},
},
Expand All @@ -92,8 +92,8 @@ func Kubeconfig(cfg *rest.Config, w io.Writer) error {
{
Name: "user",
AuthInfo: appsv1.AuthInfo{
ClientCertificateData: cfg.TLSClientConfig.CertData,
ClientKeyData: cfg.TLSClientConfig.KeyData,
ClientCertificateData: cfg.CertData,
ClientKeyData: cfg.KeyData,
Token: cfg.BearerToken,
Username: cfg.Username,
Password: cfg.Password,
Expand Down
10 changes: 5 additions & 5 deletions internal/kubernetes/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ func convertUnstructured(in client.Object) (client.Object, error) {
if group != kuttlGroup {
return in, nil
}
switch {
case kind == "TestFile":
switch kind {
case "TestFile":
converted = &v1beta1.TestFile{}
case kind == "TestStep":
case "TestStep":
converted = &v1beta1.TestStep{}
case kind == "TestAssert":
case "TestAssert":
converted = &v1beta1.TestAssert{}
case kind == "TestSuite":
case "TestSuite":
converted = &v1beta1.TestSuite{}
default:
return in, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/kuttlctl/cmd/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ func TestParseVars(t *testing.T) {
},
"unicode and special characters": {
input: map[string]string{
"unicode": "测试",
"unicode": "测试", //nolint:gosmopolitan // Unicode test data
"emoji": "🚀",
"special_chars": "name@domain.com",
"with_quotes": `"quoted string"`,
"with_backslash": `path\to\file`,
},
expected: map[string]any{
"unicode": "测试",
"unicode": "测试", //nolint:gosmopolitan // Unicode test data
"emoji": "🚀",
"special_chars": "name@domain.com",
"with_quotes": "quoted string",
Expand Down
122 changes: 44 additions & 78 deletions internal/step/step_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,44 @@ func TestMain(m *testing.M) {
}

func TestCheckResourceIntegration(t *testing.T) {
// Helper function to create nginx container spec
createNginxContainerSpec := func() map[string]interface{} {
return map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
}
}

// Helper function to create a pod with labels and nginx container
createPodWithLabels := func(name string, labels map[string]string) client.Object {
return kubernetes.WithSpec(t, kubernetes.WithLabels(t, kubernetes.NewPod(name, ""), labels), createNginxContainerSpec())
}

// Common expected pod object
expectedNginxPod := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Pod",
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
},
},
}

for _, test := range []struct {
testName string
actual []client.Object
Expand All @@ -53,90 +91,18 @@ func TestCheckResourceIntegration(t *testing.T) {
{
testName: "match object by labels, first in list matches",
actual: []client.Object{
kubernetes.WithSpec(t, kubernetes.WithLabels(t, kubernetes.NewPod("labels-match-pod", ""), map[string]string{
"app": "nginx",
}), map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
}),
kubernetes.WithSpec(t, kubernetes.WithLabels(t, kubernetes.NewPod("bb", ""), map[string]string{
"app": "not-match",
}), map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
}),
},
expected: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Pod",
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
},
},
createPodWithLabels("labels-match-pod", map[string]string{"app": "nginx"}),
createPodWithLabels("bb", map[string]string{"app": "not-match"}),
},
expected: expectedNginxPod,
},
{
testName: "match object by labels, last in list matches",
actual: []client.Object{
kubernetes.WithSpec(t, kubernetes.WithLabels(t, kubernetes.NewPod("last-in-list", ""), map[string]string{
"app": "not-match",
}), map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
}),
kubernetes.WithSpec(t, kubernetes.WithLabels(t, kubernetes.NewPod("bb", ""), map[string]string{
"app": "nginx",
}), map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
}),
},
expected: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Pod",
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
},
},
createPodWithLabels("last-in-list", map[string]string{"app": "not-match"}),
createPodWithLabels("bb", map[string]string{"app": "nginx"}),
},
expected: expectedNginxPod,
},
{
testName: "match object by labels, does not exist",
Expand Down
18 changes: 9 additions & 9 deletions internal/utils/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func (o byFirstTimestamp) Len() int { return len(o) }
func (o byFirstTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }

func (o byFirstTimestamp) Less(i, j int) bool {
if o[i].ObjectMeta.CreationTimestamp.Equal(&o[j].ObjectMeta.CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].ObjectMeta.CreationTimestamp.Before(&o[j].ObjectMeta.CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

// byFirstTimestampV1 sorts a slice of eventsv1 by first timestamp, using their involvedObject's name as a tie breaker.
Expand All @@ -33,10 +33,10 @@ func (o byFirstTimestampV1) Len() int { return len(o) }
func (o byFirstTimestampV1) Swap(i, j int) { o[i], o[j] = o[j], o[i] }

func (o byFirstTimestampV1) Less(i, j int) bool {
if o[i].ObjectMeta.CreationTimestamp.Equal(&o[j].ObjectMeta.CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].ObjectMeta.CreationTimestamp.Before(&o[j].ObjectMeta.CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

// byFirstTimestampCoreV1 sorts a slice of corev1 by first timestamp, using their involvedObject's name as a tie breaker.
Expand All @@ -46,10 +46,10 @@ func (o byFirstTimestampCoreV1) Len() int { return len(o) }
func (o byFirstTimestampCoreV1) Swap(i, j int) { o[i], o[j] = o[j], o[i] }

func (o byFirstTimestampCoreV1) Less(i, j int) bool {
if o[i].ObjectMeta.CreationTimestamp.Equal(&o[j].ObjectMeta.CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].ObjectMeta.CreationTimestamp.Before(&o[j].ObjectMeta.CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

// CollectAndLog retrieves event resources for a given namespace and logs them with the logger.
Expand Down Expand Up @@ -124,7 +124,7 @@ func printEventsBeta1(events []eventsbeta1.Event, logger testutils.Logger) {
for _, e := range events {
// time type regarding action reason note reportingController related
logger.Logf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
e.ObjectMeta.CreationTimestamp,
e.CreationTimestamp,
e.Type,
shortString(&e.Regarding),
e.Action,
Expand All @@ -139,7 +139,7 @@ func printEventsV1(events []eventsv1.Event, logger testutils.Logger) {
for _, e := range events {
// time type regarding action reason note reportingController related
logger.Logf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
e.ObjectMeta.CreationTimestamp,
e.CreationTimestamp,
e.Type,
shortString(&e.Regarding),
e.Action,
Expand All @@ -154,7 +154,7 @@ func printEventsCoreV1(events []corev1.Event, logger testutils.Logger) {
for _, e := range events {
// time type regarding action reason note reportingController related
logger.Logf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
e.ObjectMeta.CreationTimestamp,
e.CreationTimestamp,
e.Type,
shortString(&e.InvolvedObject),
e.Action,
Expand Down