Skip to content

Commit

Permalink
chore: format with gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Oct 23, 2024
1 parent c30c0fd commit 54ff757
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 55 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,28 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
go-version: 1.22.x

- name: Install Golines and GoFumpt
run: |
go install github.com/segmentio/golines@latest
go install mvdan.cc/gofumpt@latest
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --timeout 5m0s --verbose

- name: Verify formatting
run: |
make lint
if [[ -n "$(git status --porcelain)" ]]; then
echo "The following files have formatting issues:"
git status --porcelain
echo "Please run 'make lint' locally and commit the changes"
exit 1
fi
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test:
lint:
golangci-lint run

if command -v golines > /dev/null 2>&1; then \
golines -m 120 -w pkg/; \
golines -m 120 -w events/; \
fi
golines -m 120 -w pkg/
golines -m 120 -w events/

gofumpt -w .
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package main
import (
"fmt"
"io"
"os"

"github.com/flanksource/is-healthy/pkg/health"
"github.com/flanksource/is-healthy/pkg/lua"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"

"os"
)

func main() {
Expand Down Expand Up @@ -37,5 +36,4 @@ func main() {
if health.IsWorse(health.HealthStatusHealthy, _health.Status) {
os.Exit(1)
}

}
1 change: 0 additions & 1 deletion pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func GetResourceHealth(
}, nil
}
return health, err

}

// GetHealthCheckFunc returns built-in health check function or nil if health check is not supported
Expand Down
4 changes: 1 addition & 3 deletions pkg/health/health_cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

var (
defaultCertExpiryWarningPeriod = time.Hour * 24 * 2
)
var defaultCertExpiryWarningPeriod = time.Hour * 24 * 2

func SetDefaultCertificateExpiryWarningPeriod(p time.Duration) {
defaultCertExpiryWarningPeriod = p
Expand Down
1 change: 0 additions & 1 deletion pkg/health/health_daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func getDaemonSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
}

func getAppsv1DaemonSetHealth(daemon *appsv1.DaemonSet) (*HealthStatus, error) {

health := HealthUnknown

if daemon.Status.NumberAvailable == daemon.Status.DesiredNumberScheduled {
Expand Down
12 changes: 5 additions & 7 deletions pkg/health/health_hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

var (
progressingStatus = &HealthStatus{
Health: HealthHealthy,
Status: HealthStatusProgressing,
Message: "Waiting to Autoscale",
}
)
var progressingStatus = &HealthStatus{
Health: HealthHealthy,
Status: HealthStatusProgressing,
Message: "Waiting to Autoscale",
}

type hpaCondition struct {
Type string
Expand Down
1 change: 0 additions & 1 deletion pkg/health/health_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func getJobHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
}

func getBatchv1JobHealth(job *batchv1.Job) (*HealthStatus, error) {

for _, condition := range job.Status.Conditions {
switch condition.Type {
case batchv1.JobFailed:
Expand Down
1 change: 0 additions & 1 deletion pkg/health/health_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ func getAppsv1StatefulSetHealth(sts *appsv1.StatefulSet) (*HealthStatus, error)
Health: health,
Status: HealthStatusRunning,
}, nil

}
52 changes: 27 additions & 25 deletions pkg/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func TestStatefulSetOnDeleteHealth(t *testing.T) {
func TestDaemonSetOnDeleteHealth(t *testing.T) {
assertAppHealth(t, "./testdata/daemonset-ondelete.yaml", health.HealthStatusRunning, health.HealthHealthy, true)
}

func TestPVCHealth(t *testing.T) {
assertAppHealth(t, "./testdata/pvc-bound.yaml", health.HealthStatusHealthy, health.HealthHealthy, true)
assertAppHealth(t, "./testdata/pvc-pending.yaml", health.HealthStatusProgressing, health.HealthHealthy, false)
Expand Down Expand Up @@ -304,7 +305,6 @@ func TestReplicaSet(t *testing.T) {
assertAppHealthWithOverwrite(t, "./testdata/replicaset-unhealthy-pods.yaml", map[string]string{
"2024-10-21T11:20:19Z": time.Now().Add(-time.Minute * 2).UTC().Format("2006-01-02T15:04:05Z"),
}, health.HealthStatusScalingUp, health.HealthUnknown, false)

}

func TestPod(t *testing.T) {
Expand Down Expand Up @@ -432,53 +432,55 @@ func TestPod(t *testing.T) {
// }

func TestGetArgoWorkflowHealth(t *testing.T) {
sampleWorkflow := unstructured.Unstructured{Object: map[string]interface{}{
"spec": map[string]interface{}{
"entrypoint": "sampleEntryPoint",
"extraneousKey": "we are agnostic to extraneous keys",
},
"status": map[string]interface{}{
"phase": "Running",
"message": "This node is running",
sampleWorkflow := unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"entrypoint": "sampleEntryPoint",
"extraneousKey": "we are agnostic to extraneous keys",
},
"status": map[string]interface{}{
"phase": "Running",
"message": "This node is running",
},
},
},
}

argohealth, err := health.GetArgoWorkflowHealth(&sampleWorkflow)
require.NoError(t, err)
assert.Equal(t, health.HealthStatusProgressing, argohealth.Status)
assert.Equal(t, "This node is running", argohealth.Message)

sampleWorkflow = unstructured.Unstructured{Object: map[string]interface{}{
"spec": map[string]interface{}{
"entrypoint": "sampleEntryPoint",
"extraneousKey": "we are agnostic to extraneous keys",
sampleWorkflow = unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"entrypoint": "sampleEntryPoint",
"extraneousKey": "we are agnostic to extraneous keys",
},
"status": map[string]interface{}{
"phase": "Succeeded",
"message": "This node is has succeeded",
},
},
"status": map[string]interface{}{
"phase": "Succeeded",
"message": "This node is has succeeded",
},
},
}

argohealth, err = health.GetArgoWorkflowHealth(&sampleWorkflow)
require.NoError(t, err)
assert.Equal(t, health.HealthStatusHealthy, argohealth.Status)
assert.Equal(t, "This node is has succeeded", argohealth.Message)

sampleWorkflow = unstructured.Unstructured{Object: map[string]interface{}{
"spec": map[string]interface{}{
"entrypoint": "sampleEntryPoint",
"extraneousKey": "we are agnostic to extraneous keys",
sampleWorkflow = unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"entrypoint": "sampleEntryPoint",
"extraneousKey": "we are agnostic to extraneous keys",
},
},
},
}

argohealth, err = health.GetArgoWorkflowHealth(&sampleWorkflow)
require.NoError(t, err)
assert.Equal(t, health.HealthStatusProgressing, argohealth.Status)
assert.Equal(t, "", argohealth.Message)

}

func TestArgoApplication(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/lua/custom_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestLuaResourceActionsScript(t *testing.T) {
}
assert.NoError(t, err)
dir := filepath.Dir(path)
//TODO: Change to path
// TODO: Change to path
yamlBytes, err := os.ReadFile(dir + "/action_test.yaml")
assert.NoError(t, err)
var resourceTest ActionTestStructure
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestLuaResourceActionsScript(t *testing.T) {
// Uncomment the following line if you need to use lua libraries debugging
// purposes. Otherwise, leave this false to ensure tests reflect the same
// privileges that API server has.
//UseOpenLibs: true,
// UseOpenLibs: true,
}
sourceObj := getObj(filepath.Join(dir, test.InputPath))
action, err := vm.GetResourceAction(sourceObj, test.Action)
Expand Down
2 changes: 0 additions & 2 deletions pkg/lua/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (vm VM) ExecuteResourceAction(obj *unstructured.Unstructured, script string
returnValue := l.Get(-1)
if returnValue.Type() == lua.LTTable {
jsonBytes, err := luajson.Encode(returnValue)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -214,7 +213,6 @@ func (vm VM) ExecuteResourceAction(obj *unstructured.Unstructured, script string
obj.Object,
)
}

}
return impactedResources, nil
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/lua/lua_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func TestExecuteNewHealthStatusFunction(t *testing.T) {
Ready: true,
}
assert.Equal(t, expectedHealthStatus, status)

}

func TestExecuteWildcardHealthStatusFunction(t *testing.T) {
Expand All @@ -108,7 +107,6 @@ func TestExecuteWildcardHealthStatusFunction(t *testing.T) {
Message: "testWildcardMessage",
}
assert.Equal(t, expectedHealthStatus, status)

}

const osLuaScript = `os.getenv("HOME")`
Expand Down Expand Up @@ -356,7 +354,6 @@ func TestExecuteResourceActionDiscoveryInvalidReturn(t *testing.T) {
actions, err := vm.ExecuteResourceActionDiscovery(testObj, invalidDiscoveryLua)
assert.Nil(t, actions)
assert.Error(t, err)

}

const validActionLua = `
Expand Down Expand Up @@ -491,6 +488,7 @@ result[2] = impactedResource2
return result
`

const mixedOperationActionLuaOk = `
job1 = {}
job1.apiVersion = "batch/v1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/lua/oslib_safe.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func osDate(L *lua.LState) int {
var cDateFlagToGo = map[byte]string{
'a': "mon", 'A': "Monday", 'b': "Jan", 'B': "January", 'c': "02 Jan 06 15:04 MST", 'd': "02",
'F': "2006-01-02", 'H': "15", 'I': "03", 'm': "01", 'M': "04", 'p': "PM", 'P': "pm", 'S': "05",
'x': "15/04/05", 'X': "15:04:05", 'y': "06", 'Y': "2006", 'z': "-0700", 'Z': "MST"}
'x': "15/04/05", 'X': "15:04:05", 'y': "06", 'Y': "2006", 'z': "-0700", 'Z': "MST",
}

func strftime(t time.Time, cfmt string) string {
sc := newFlagScanner('%', "", "", cfmt)
Expand Down

0 comments on commit 54ff757

Please sign in to comment.