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

Configure circleci config #13

Merged
merged 4 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
62 changes: 62 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 2.1

orbs:
architect: giantswarm/[email protected]

workflows:
go-build:
jobs:
- architect/go-build:
name: go-build
binary: heartbeatctl
filters:
# Needed to trigger job also on git tag.
tags:
only: /^v.*/

- architect/go-build:
name: go-build-heartbeatctl-linux-amd64
binary: build/heartbeatctl-linux-amd64/heartbeatctl
os: linux
filters:
branches:
only: main
# Needed to trigger job also on git tag.
tags:
only: /^v.*/

- architect/go-build:
name: go-build-heartbeatctl-darwin-amd64
binary: build/heartbeatctl-darwin-amd64/heartbeatctl
os: darwin
filters:
branches:
only: main
# Needed to trigger job also on git tag.
tags:
only: /^v.*/

- architect/push-to-docker:
name: push-to-quay
context: "architect"
image: quay.io/giantswarm/heartbeatctl
username_envar: QUAY_USERNAME
password_envar: QUAY_PASSWORD
requires:
- go-build
filters:
# Needed to trigger job also on git tag.
tags:
only: /^v.*/

- architect/push-to-docker:
name: push-to-docker
context: "architect"
image: "docker.io/giantswarm/heartbeatctl"
username_envar: "DOCKER_USERNAME"
password_envar: "DOCKER_PASSWORD"
requires:
- go-build
filters:
tags:
only: /^v.*/
Copy link
Member

Choose a reason for hiding this comment

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

What about the EOF here ? Please keep it

5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:3.16.2

ADD ./heartbeatctl /usr/local/bin/heartbeatctl

ENTRYPOINT ["/usr/local/bin/heartbeatctl"]
25 changes: 22 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
module github.com/giantswarm/heartbeatctl

go 1.14
go 1.17

require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/golang/mock v1.6.0
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.20.2
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.13
github.com/ryanuber/columnize v2.1.2+incompatible
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
k8s.io/apimachinery v0.20.1
k8s.io/apimachinery v0.24.0
)

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-retryablehttp v0.5.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
)
102 changes: 56 additions & 46 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pkg/client/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func New(cfg *client.Config) (Port, error) {
}

if cfg.Logger == nil {
cfg.Logger = logrus.New()
cfg.Logger.SetLevel(logrus.PanicLevel)
logger := logrus.New()
logger.SetLevel(logrus.InfoLevel)
cfg.Logger = logger
}

return heartbeat.NewClient(cfg)
Expand Down
50 changes: 28 additions & 22 deletions pkg/ctl/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import (
"github.com/giantswarm/heartbeatctl/pkg/mocks"
)

const (
GetMethodName = "Get"
EnableMethodName = "Enable"
DisableMethodName = "Disable"
)

func getName(h heartbeat.Heartbeat) string {
return h.Name
}
Expand Down Expand Up @@ -108,7 +114,7 @@ var _ = Describe("Adapter", func() {
}
})

Context("Get", func() {
Context(GetMethodName, func() {
DescribeTable(
"filters elements correctly",
func(opts *ctl.SelectorConfig, expected ...string) {
Expand Down Expand Up @@ -181,9 +187,9 @@ var _ = Describe("Adapter", func() {

// setup the right expectation, depending on
// which method we're asserting
if methodName == "Enable" {
if methodName == EnableMethodName {
repo.EXPECT().Enable(gomock.Any(), hbName).Return(hbi, nil)
} else if methodName == "Disable" {
} else if methodName == DisableMethodName {
// in case of disable a successful call
// would set `Enabled` to false
hbi.Enabled = false
Expand All @@ -196,7 +202,7 @@ var _ = Describe("Adapter", func() {

It(fmt.Sprintf("calls %s on heartbeats selected by given options", methodName), func() {
method := adapter.Enable
if methodName == "Disable" {
if methodName == DisableMethodName {
method = adapter.Disable
}

Expand All @@ -209,8 +215,8 @@ var _ = Describe("Adapter", func() {
})
}

AssertMethodCalledOnSelectedHeartbeats("Enable")
AssertMethodCalledOnSelectedHeartbeats("Disable")
AssertMethodCalledOnSelectedHeartbeats(EnableMethodName)
AssertMethodCalledOnSelectedHeartbeats(DisableMethodName)

AssertMethodFailsFastWhenRepoCallFails := func(methodName string) {
Context(methodName, func() {
Expand All @@ -224,18 +230,18 @@ var _ = Describe("Adapter", func() {
}
apiErr := errors.New("API call failed")

if methodName == "Enable" {
if methodName == EnableMethodName {
repo.EXPECT().Enable(gomock.Any(), "foo").Return(fooHbi, nil)
repo.EXPECT().Enable(gomock.Any(), "foo-oof1").Return(nil, apiErr)
} else if methodName == "Disable" {
} else if methodName == DisableMethodName {
repo.EXPECT().Disable(gomock.Any(), "foo").Return(fooHbi, nil)
repo.EXPECT().Disable(gomock.Any(), "foo-oof1").Return(nil, apiErr)
}

By("calling adapter method")

method := adapter.Enable
if methodName == "Disable" {
if methodName == DisableMethodName {
method = adapter.Disable
}
hbInfos, err := method(&ctl.SelectorConfig{
Expand All @@ -260,16 +266,16 @@ var _ = Describe("Adapter", func() {
})
}

AssertMethodFailsFastWhenRepoCallFails("Enable")
AssertMethodFailsFastWhenRepoCallFails("Disable")
AssertMethodFailsFastWhenRepoCallFails(EnableMethodName)
AssertMethodFailsFastWhenRepoCallFails(DisableMethodName)
})

When("no heartbeats are configured", func() {
BeforeEach(func() {
configuredHeartbeats = []heartbeat.Heartbeat{}
})

Context("Get", func() {
Context(GetMethodName, func() {
It("returns an empty list and no error", func() {
Expect(adapter.Get(&ctl.SelectorConfig{})).To(BeEmpty())
})
Expand Down Expand Up @@ -303,11 +309,11 @@ var _ = Describe("Adapter", func() {
opts := &ctl.SelectorConfig{NameExpressions: []string{".*"}}

switch methodName {
case "Get":
case GetMethodName:
_, err = adapter.Get(opts)
case "Enable":
case EnableMethodName:
_, err = adapter.Enable(opts)
case "Disable":
case DisableMethodName:
_, err = adapter.Disable(opts)
}

Expand All @@ -317,18 +323,18 @@ var _ = Describe("Adapter", func() {
})
}

AssertMethodPropagatesError("Get")
AssertMethodPropagatesError("Enable")
AssertMethodPropagatesError("Disable")
AssertMethodPropagatesError(GetMethodName)
AssertMethodPropagatesError(EnableMethodName)
AssertMethodPropagatesError(DisableMethodName)
})

When("no selectors are given", func() {
var methods map[string]func(*ctl.SelectorConfig) ([]heartbeat.HeartbeatInfo, error)

BeforeEach(func() {
methods = map[string]func(*ctl.SelectorConfig) ([]heartbeat.HeartbeatInfo, error){
"Enable": adapter.Enable,
"Disable": adapter.Disable,
EnableMethodName: adapter.Enable,
DisableMethodName: adapter.Disable,
}
})

Expand All @@ -346,8 +352,8 @@ var _ = Describe("Adapter", func() {
})
}

AssertMethodFails("Enable")
AssertMethodFails("Disable")
AssertMethodFails(EnableMethodName)
AssertMethodFails(DisableMethodName)
})
})
})
1 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tools
Copy link
Member

Choose a reason for hiding this comment

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

What is this line for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This lines tells go that the imports in this file are not to be added to the go modules as they are build dependencies.
This file had // +build tools earlier so go generate can work but circleci requires //go:build tools

Copy link
Member

Choose a reason for hiding this comment

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

I think this might be because we might have different go version here and in CI

// +build tools

// This file imports packages that are used when running go generate, or used
Expand Down