Skip to content

Commit

Permalink
Merge pull request #776 from cprivitere/main
Browse files Browse the repository at this point in the history
🐛 Fix CI Cleanup
  • Loading branch information
cprivitere authored Jun 28, 2024
2 parents e1334ef + c8a6282 commit fa95e86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ name: Cleanup
on:
schedule:
- cron: "0 */2 * * *" # TODO: Run every 4 hours to soak test, should be less frequent before merge (weekly/daily/???)
workflow_dispatch:
jobs:
cleanup:
name: Cleanup any orphaned CI Resources
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- name: Run the cleanup tool
run: go run ./cmd/ci-clean
env:
PACKET_API_KEY: ${{ secrets.PACKET_API_TOKEN }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "./go.mod"
- name: Run the cleanup tool
run: go run ./cmd/ci-clean
env:
PACKET_API_KEY: ${{ secrets.PACKET_API_TOKEN }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
24 changes: 12 additions & 12 deletions internal/emlb/emlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type EMLB struct {
client *lbaas.APIClient
metro string
projectID string
tokenExchanger *TokenExchanger
TokenExchanger *TokenExchanger
}

// NewEMLB creates a new Equinix Metal Load Balancer API client object.
Expand All @@ -86,7 +86,7 @@ func NewEMLB(metalAPIKey, projectID, metro string) *EMLB {
emlbConfig.Debug = checkDebugEnabled()

manager.client = lbaas.NewAPIClient(emlbConfig)
manager.tokenExchanger = &TokenExchanger{
manager.TokenExchanger = &TokenExchanger{
metalAPIKey: metalAPIKey,
tokenExchangeURL: loadbalancerTokenExchnageURL,
client: manager.client.GetConfig().HTTPClient,
Expand Down Expand Up @@ -286,31 +286,31 @@ func (e *EMLB) DeleteLoadBalancerOrigin(ctx context.Context, machineScope *scope

// GetLoadBalancers returns a Load Balancer Collection of all the Equinix Metal Load Balancers in a project.
func (e *EMLB) GetLoadBalancers(ctx context.Context) (*lbaas.LoadBalancerCollection, *http.Response, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

LoadBalancerCollection, resp, err := e.client.ProjectsApi.ListLoadBalancers(ctx, e.projectID).Execute()
return LoadBalancerCollection, resp, err
}

// GetLoadBalancerPools returns a Load Balancer Collection of all the Equinix Metal Load Balancers in a project.
func (e *EMLB) GetLoadBalancerPools(ctx context.Context) (*lbaas.LoadBalancerPoolCollection, *http.Response, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

LoadBalancerPoolCollection, resp, err := e.client.ProjectsApi.ListPools(ctx, e.projectID).Execute()
return LoadBalancerPoolCollection, resp, err
}

// getLoadBalancer Returns a Load Balancer object given an id.
func (e *EMLB) getLoadBalancer(ctx context.Context, id string) (*lbaas.LoadBalancer, *http.Response, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

LoadBalancer, resp, err := e.client.LoadBalancersApi.GetLoadBalancer(ctx, id).Execute()
return LoadBalancer, resp, err
}

// getLoadBalancerPort Returns a Load Balancer Port object given an id.
func (e *EMLB) getLoadBalancerPort(ctx context.Context, id string, portNumber int32) (*lbaas.LoadBalancerPort, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

LoadBalancerPort, _, err := e.client.PortsApi.GetLoadBalancerPort(ctx, id, portNumber).Execute()
return LoadBalancerPort, err
Expand All @@ -319,7 +319,7 @@ func (e *EMLB) getLoadBalancerPort(ctx context.Context, id string, portNumber in
// EnsureLoadBalancerOrigin takes the devices list of IP addresses in a Load Balancer Origin Pool and ensures an origin
// for the first IPv4 address in the list exists.
func (e *EMLB) ensureLoadBalancerOrigin(ctx context.Context, originID, poolID, lbName string, deviceAddr []corev1.NodeAddress) (*lbaas.LoadBalancerPoolOrigin, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)
log := ctrl.LoggerFrom(ctx)

if originID == "" {
Expand Down Expand Up @@ -372,7 +372,7 @@ func (e *EMLB) ensureLoadBalancerOrigin(ctx context.Context, originID, poolID, l

// ensureLoadBalancerPool checks if the poolID exists and if not, creates it.
func (e *EMLB) ensureLoadBalancerPool(ctx context.Context, poolID, lbName string) (*lbaas.LoadBalancerPool, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

// Pool doesn't exist, so let's create it.
if poolID == "" {
Expand All @@ -391,7 +391,7 @@ func (e *EMLB) ensureLoadBalancerPool(ctx context.Context, poolID, lbName string

// ensureLoadBalancer Takes a Load Balancer id and ensures those pools and ensures it exists.
func (e *EMLB) ensureLoadBalancer(ctx context.Context, lbID, lbname string, portNumber int32) (*lbaas.LoadBalancer, *lbaas.LoadBalancerPort, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

// EMLB doesn't exist, so let's create it.
if lbID == "" {
Expand Down Expand Up @@ -470,18 +470,18 @@ func (e *EMLB) createOrigin(ctx context.Context, poolID, originName string, targ

// DeleteLoadBalancer deletes an Equinix Metal Load Balancer given an ID.
func (e *EMLB) DeleteLoadBalancer(ctx context.Context, lbID string) (*http.Response, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)
return e.client.LoadBalancersApi.DeleteLoadBalancer(ctx, lbID).Execute()
}

// DeleteLoadBalancerPool deletes an Equinix Metal Load Balancer Origin Pool given an ID.
func (e *EMLB) DeleteLoadBalancerPool(ctx context.Context, poolID string) (*http.Response, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)
return e.client.PoolsApi.DeleteLoadBalancerPool(ctx, poolID).Execute()
}

func (e *EMLB) updateListenerPort(ctx context.Context, poolID, lbPortID string) (*lbaas.LoadBalancerPort, error) {
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger)
ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.TokenExchanger)

// Create a listener port update request that adds the provided load balancer origin pool to the listener port.
portUpdateRequest := lbaas.LoadBalancerPortUpdate{
Expand Down
2 changes: 1 addition & 1 deletion internal/emlb/emlb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestNewEMLB(t *testing.T) {
g.Expect(emlb.client).To(Not(BeNil()))

// assert tokenExchanger is not nil
g.Expect(emlb.tokenExchanger).To(Not(BeNil()))
g.Expect(emlb.TokenExchanger).To(Not(BeNil()))

// assert project ID is correct
g.Expect(emlb.projectID).To(Equal(projectID))
Expand Down

0 comments on commit fa95e86

Please sign in to comment.