From fd93073ab91ec545a8c9e7c435b08420f175ed0b Mon Sep 17 00:00:00 2001 From: Fredrik Thune Date: Tue, 31 Oct 2023 11:34:56 +0100 Subject: [PATCH 1/5] Adds cache to GA docker build to speedup build times --- .github/workflows/pull_request.yml | 3 ++- .github/workflows/push.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7e565075..455ed3ae 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -103,7 +103,8 @@ jobs: pull: true push: true build-args: BUILD_PARAMETERS=${{ env.BUILD_PARAMETERS }} - cache-to: type=inline + cache-from: type=gha + cache-to: type=gha,mode=max platforms: linux/amd64,linux/arm,linux/arm64 tags: | ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 317729c6..a5efb27b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -113,7 +113,8 @@ jobs: pull: true push: true build-args: BUILD_PARAMETERS=${{ env.BUILD_PARAMETERS }} - cache-to: type=inline + cache-from: type=gha + cache-to: type=gha,mode=max platforms: linux/amd64,linux/arm,linux/arm64 tags: | ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.new_tag }} From ac8f65336e77bd6d4796935b5ed98b1bf6686b7e Mon Sep 17 00:00:00 2001 From: Fredrik Thune Date: Tue, 31 Oct 2023 16:31:16 +0100 Subject: [PATCH 2/5] Configures logger for all test files to allow logs to log on failed test --- pkg/config/config_test.go | 8 ++++++++ pkg/http/httpClient_test.go | 8 ++++++++ pkg/kube/wrappers/ingress-wrapper_test.go | 8 ++++++++ pkg/kube/wrappers/routeWrapper_test.go | 8 ++++++++ pkg/monitors/appinsights/appinsights-monitor_test.go | 8 ++++++++ pkg/monitors/grafana/grafana-monitor_test.go | 8 ++++++++ pkg/monitors/monitor-proxy_test.go | 8 ++++++++ pkg/monitors/pingdom/pingdom-monitor_test.go | 8 ++++++++ pkg/monitors/statuscake/statuscake-monitor_test.go | 8 ++++++++ pkg/monitors/updown/updown-monitor_test.go | 8 ++++++++ pkg/monitors/uptime/uptime-mappers_test.go | 8 ++++++++ pkg/monitors/uptime/uptime-monitor_test.go | 8 ++++++++ pkg/monitors/uptimerobot/uptime-mappers_test.go | 8 ++++++++ pkg/monitors/uptimerobot/uptime-monitor_test.go | 8 ++++++++ pkg/monitors/uptimerobot/uptime-status-page.go | 8 ++++++++ 15 files changed, 120 insertions(+) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 8fd92b7c..9bf9f395 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -2,9 +2,17 @@ package config import ( "reflect" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" "testing" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + const ( configFilePath = "../../examples/configs/test-config-uptimerobot.yaml" correctTestConfigName = "UptimeRobot" diff --git a/pkg/http/httpClient_test.go b/pkg/http/httpClient_test.go index 5cefda1e..032b6a03 100644 --- a/pkg/http/httpClient_test.go +++ b/pkg/http/httpClient_test.go @@ -2,9 +2,17 @@ package http import ( "net/http" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" "testing" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestCreateHttpClient(t *testing.T) { url := "https://google.com" client := CreateHttpClient(url) diff --git a/pkg/kube/wrappers/ingress-wrapper_test.go b/pkg/kube/wrappers/ingress-wrapper_test.go index 9e83ebe4..4a7557f7 100644 --- a/pkg/kube/wrappers/ingress-wrapper_test.go +++ b/pkg/kube/wrappers/ingress-wrapper_test.go @@ -5,10 +5,18 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/util" v1 "k8s.io/api/networking/v1" + ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" fakekubeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + const ( testUrl = "testurl.stackator.com" ) diff --git a/pkg/kube/wrappers/routeWrapper_test.go b/pkg/kube/wrappers/routeWrapper_test.go index 34d2dabb..cfd5fee4 100644 --- a/pkg/kube/wrappers/routeWrapper_test.go +++ b/pkg/kube/wrappers/routeWrapper_test.go @@ -5,10 +5,18 @@ import ( routev1 "github.com/openshift/api/route/v1" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" fakekubeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + const ( routeTestUrl = "testurl.stackator.com/" ) diff --git a/pkg/monitors/appinsights/appinsights-monitor_test.go b/pkg/monitors/appinsights/appinsights-monitor_test.go index 27b05eaf..e6078e6d 100644 --- a/pkg/monitors/appinsights/appinsights-monitor_test.go +++ b/pkg/monitors/appinsights/appinsights-monitor_test.go @@ -11,8 +11,16 @@ import ( insightsAlert "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights" endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1" "github.com/stakater/IngressMonitorController/v2/pkg/models" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestAppinsightsMonitorService_createWebTest(t *testing.T) { location := "westeurope" diff --git a/pkg/monitors/grafana/grafana-monitor_test.go b/pkg/monitors/grafana/grafana-monitor_test.go index ab97c727..ec048d7d 100644 --- a/pkg/monitors/grafana/grafana-monitor_test.go +++ b/pkg/monitors/grafana/grafana-monitor_test.go @@ -5,9 +5,17 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/config" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" "testing" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestAddMonitorWithCorrectValues(t *testing.T) { config := config.GetControllerConfigTest() diff --git a/pkg/monitors/monitor-proxy_test.go b/pkg/monitors/monitor-proxy_test.go index 9557bb2d..2ce711df 100644 --- a/pkg/monitors/monitor-proxy_test.go +++ b/pkg/monitors/monitor-proxy_test.go @@ -4,8 +4,16 @@ import ( "testing" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestMonitorServiceProxyOfTypeWithCorrectType(t *testing.T) { monitorType := "UptimeRobot" uptime := (&MonitorServiceProxy{}).OfType(monitorType) diff --git a/pkg/monitors/pingdom/pingdom-monitor_test.go b/pkg/monitors/pingdom/pingdom-monitor_test.go index 90311113..b2723e27 100644 --- a/pkg/monitors/pingdom/pingdom-monitor_test.go +++ b/pkg/monitors/pingdom/pingdom-monitor_test.go @@ -7,8 +7,16 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/config" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestAddMonitorWithCorrectValues(t *testing.T) { config := config.GetControllerConfigTest() diff --git a/pkg/monitors/statuscake/statuscake-monitor_test.go b/pkg/monitors/statuscake/statuscake-monitor_test.go index d8aae128..11572cd4 100644 --- a/pkg/monitors/statuscake/statuscake-monitor_test.go +++ b/pkg/monitors/statuscake/statuscake-monitor_test.go @@ -10,8 +10,16 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" "gotest.tools/assert" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestAddMonitorWithCorrectValues(t *testing.T) { config := config.GetControllerConfigTest() diff --git a/pkg/monitors/updown/updown-monitor_test.go b/pkg/monitors/updown/updown-monitor_test.go index 87e34040..59589319 100644 --- a/pkg/monitors/updown/updown-monitor_test.go +++ b/pkg/monitors/updown/updown-monitor_test.go @@ -9,8 +9,16 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" "github.com/stretchr/testify/assert" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + type Block struct { Try func() Catch func(Exception) diff --git a/pkg/monitors/uptime/uptime-mappers_test.go b/pkg/monitors/uptime/uptime-mappers_test.go index b0262768..9a87f3eb 100644 --- a/pkg/monitors/uptime/uptime-mappers_test.go +++ b/pkg/monitors/uptime/uptime-mappers_test.go @@ -7,8 +7,16 @@ import ( endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1" "github.com/stakater/IngressMonitorController/v2/pkg/models" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestUptimeMonitorMonitorToBaseMonitorMapper(t *testing.T) { uptimeMonitorObject := UptimeMonitorMonitor{Name: "Test Monitor", PK: 124, diff --git a/pkg/monitors/uptime/uptime-monitor_test.go b/pkg/monitors/uptime/uptime-monitor_test.go index 917e333d..d92ee2b6 100644 --- a/pkg/monitors/uptime/uptime-monitor_test.go +++ b/pkg/monitors/uptime/uptime-monitor_test.go @@ -7,8 +7,16 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/config" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestGetAllMonitors(t *testing.T) { config := config.GetControllerConfigTest() diff --git a/pkg/monitors/uptimerobot/uptime-mappers_test.go b/pkg/monitors/uptimerobot/uptime-mappers_test.go index 0dfa8d31..d9e37947 100644 --- a/pkg/monitors/uptimerobot/uptime-mappers_test.go +++ b/pkg/monitors/uptimerobot/uptime-mappers_test.go @@ -9,8 +9,16 @@ import ( endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + func TestUptimeMonitorMonitorToBaseMonitorMapper(t *testing.T) { uptimeMonitorObject := UptimeMonitorMonitor{FriendlyName: "Test Monitor", ID: 124, URL: "https://stakater.com", Interval: 900} diff --git a/pkg/monitors/uptimerobot/uptime-monitor_test.go b/pkg/monitors/uptimerobot/uptime-monitor_test.go index f108945c..bbeb8809 100644 --- a/pkg/monitors/uptimerobot/uptime-monitor_test.go +++ b/pkg/monitors/uptimerobot/uptime-monitor_test.go @@ -8,8 +8,16 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/config" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + // Not a test case. Cleanup to remove added dummy Monitors func TestRemoveDanglingMonitors(t *testing.T) { config := config.GetControllerConfigTest() diff --git a/pkg/monitors/uptimerobot/uptime-status-page.go b/pkg/monitors/uptimerobot/uptime-status-page.go index 7c7b6a99..45fe5d55 100644 --- a/pkg/monitors/uptimerobot/uptime-status-page.go +++ b/pkg/monitors/uptimerobot/uptime-status-page.go @@ -12,9 +12,17 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/http" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" + ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) +func init() { + // To allow normal logging to be printed if tests fails + // Dev mode is an extra feature to make output more readable + ctrl.SetLogger(zap.New(zap.UseDevMode(true))) +} + var log = logf.Log.WithName("uptime-monitor-test") type UpTimeStatusPageService struct { From eaa0e0d19a47b3686c64a00ad12cca4a48d8f6fb Mon Sep 17 00:00:00 2001 From: Fredrik Thune Date: Tue, 31 Oct 2023 17:00:19 +0100 Subject: [PATCH 3/5] Adds log for nocontent on remove monitor in statuscake --- pkg/monitors/statuscake/statuscake-monitor.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/monitors/statuscake/statuscake-monitor.go b/pkg/monitors/statuscake/statuscake-monitor.go index 9bc95e67..c94abe83 100644 --- a/pkg/monitors/statuscake/statuscake-monitor.go +++ b/pkg/monitors/statuscake/statuscake-monitor.go @@ -440,6 +440,7 @@ func (service *StatusCakeMonitorService) Remove(m models.Monitor) { log.Error(nil, fmt.Sprintf("Delete Request failed for Monitor: %s with id: %s", m.Name, m.ID)) } else { + log.Info("Statuscode for Remove monitor is 'StatusNoContent'") _, err = service.GetByID(m.ID) if strings.Contains(err.Error(), "Request failed") { log.Info("Monitor Deleted: " + m.ID + m.Name) From a7ee17ad252c4bb72edd33f1377e6b2a0a1dd939 Mon Sep 17 00:00:00 2001 From: Fredrik Thune Date: Wed, 1 Nov 2023 11:28:07 +0100 Subject: [PATCH 4/5] Updates lint version in build GA workflow --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a5efb27b..c1f70651 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -43,7 +43,7 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3 with: - version: v1.50.1 + version: v1.54 only-new-issues: false args: --timeout 10m From 4abafdedc2ef3e9a4467868d4d5080b22011afd7 Mon Sep 17 00:00:00 2001 From: Fredrik Thune Date: Wed, 1 Nov 2023 11:38:50 +0100 Subject: [PATCH 5/5] Removed log row and wrongly placed configured --- pkg/monitors/statuscake/statuscake-monitor.go | 1 - pkg/monitors/uptimerobot/uptime-status-page.go | 8 -------- 2 files changed, 9 deletions(-) diff --git a/pkg/monitors/statuscake/statuscake-monitor.go b/pkg/monitors/statuscake/statuscake-monitor.go index c94abe83..9bc95e67 100644 --- a/pkg/monitors/statuscake/statuscake-monitor.go +++ b/pkg/monitors/statuscake/statuscake-monitor.go @@ -440,7 +440,6 @@ func (service *StatusCakeMonitorService) Remove(m models.Monitor) { log.Error(nil, fmt.Sprintf("Delete Request failed for Monitor: %s with id: %s", m.Name, m.ID)) } else { - log.Info("Statuscode for Remove monitor is 'StatusNoContent'") _, err = service.GetByID(m.ID) if strings.Contains(err.Error(), "Request failed") { log.Info("Monitor Deleted: " + m.ID + m.Name) diff --git a/pkg/monitors/uptimerobot/uptime-status-page.go b/pkg/monitors/uptimerobot/uptime-status-page.go index 45fe5d55..7c7b6a99 100644 --- a/pkg/monitors/uptimerobot/uptime-status-page.go +++ b/pkg/monitors/uptimerobot/uptime-status-page.go @@ -12,17 +12,9 @@ import ( "github.com/stakater/IngressMonitorController/v2/pkg/http" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" - ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/log/zap" ) -func init() { - // To allow normal logging to be printed if tests fails - // Dev mode is an extra feature to make output more readable - ctrl.SetLogger(zap.New(zap.UseDevMode(true))) -} - var log = logf.Log.WithName("uptime-monitor-test") type UpTimeStatusPageService struct {