Skip to content

Commit

Permalink
Re-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
andreev-io committed Jan 23, 2025
1 parent 34d4161 commit b2c2f28
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 142 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: golangci-lint
on:
pull_request:
paths:
- '**'
push:
branches:
- main
paths:
- '**'

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
9 changes: 2 additions & 7 deletions .github/workflows/kubenetmon.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI Workflow
name: Main workflow

on:
pull_request:
Expand All @@ -25,11 +25,6 @@ jobs:
cache: true
cache-dependency-path: go.sum

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60

- name: Run tests
run: |
make test
Expand All @@ -47,7 +42,7 @@ jobs:
helm template kubenetmon/deploy/helm | kubectl apply --dry-run=client -f -
build-and-publish:
name: Build and Publish Docker and Helm Chart
name: Build and publish Docker image and Helm chart
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: lint-and-test
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint: ## Run linters.
echo "golangci-lint not found. Install it with 'make golangci-lint'"; \
exit 1; \
fi
golangci-lint --allow-parallel-runners --fast --fix --verbose ./...
golangci-lint run --allow-parallel-runners --fast --fix --verbose ./...

vendor: ## Vendor dependencies.
go mod vendor -v
Expand Down
14 changes: 0 additions & 14 deletions pkg/labeler/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ func (m ConnectionFlags) String() string {
return strings.ReplaceAll(string(b), "\"", "'")
}

// List of ClickHouse Server ports that are only used by customers. We can bill
// for all traffic on them.
//
// 8124 is used for HTTP with PROXY.
//
// 8443 is used for HTTPS (terminated by ClickHouse).
//
// 9004 is used for MySQL.
//
// 9011 is used by native protocol with PROXY.
//
// 9440 is used by native protocol with TLS (terminated by ClickHouse).
var customerExclusiveClickHouseServerPorts = []uint16{8124, 8443, 9004, 9011, 9440}

// FlowdData describes all the information needed for all Prometheus metrics
// related to a conntrack connection (one flow toward the local pod, one flow
// out of the local pod).
Expand Down
65 changes: 0 additions & 65 deletions pkg/labeler/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package labeler

import (
"fmt"
"net"
"sync"
"time"

Expand Down Expand Up @@ -32,11 +31,6 @@ type RemoteLabeler struct {
cloud Cloud
}

type azDetail struct {
region string
azID string
}

var (
publicIPRefreshCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Expand Down Expand Up @@ -214,62 +208,3 @@ func getCloudRanges() (awsIPRanges AWSIPRanges, gcpIPRanges GCPIPRanges, googleI

return
}

// getCloudRegions builds a list of regions for the requested cloud.
func getCloudRegions(cloud Cloud, ipRanges interface{}) ([]string, error) {
var (
uniqRegions = make(map[string]struct{})
regions = make([]string, 0)
)

switch cloud {
case AWS:
awsIPRanges := ipRanges.(AWSIPRanges)
for _, p := range awsIPRanges.Prefixes {
if _, ok := uniqRegions[p.Region]; !ok {
regions = append(regions, NormalizeCloudString(p.Region))
uniqRegions[p.Region] = struct{}{}
}
}
case GCP:
gcpIPRanges := ipRanges.(GCPIPRanges)
for _, p := range gcpIPRanges.Prefixes {
if _, ok := uniqRegions[p.Scope]; !ok {
regions = append(regions, NormalizeCloudString(p.Scope))
uniqRegions[p.Scope] = struct{}{}
}
}
case Azure:
azureIPRanges := ipRanges.(AzureIPRanges)
for _, pg := range azureIPRanges.PrefixGroups {
region := pg.Properties.Region
if region == "" {
region = AzureGlobalRegion
}

if _, ok := uniqRegions[region]; !ok {
regions = append(regions, region)
uniqRegions[region] = struct{}{}
}
}
}

return regions, nil
}

// tryGetHostIPs gets all IPs for the host and doesn't return an error when the
// host doesn't exist.
func tryGetHostIPs(host string) ([]net.IP, error) {
ips, err := net.LookupIP(host)
if err != nil {
if e, ok := err.(*net.DNSError); ok {
if e.IsNotFound {
return nil, nil
}
}

return nil, fmt.Errorf("could not resolve host %v: %w", host, err)
}

return ips, nil
}
55 changes: 0 additions & 55 deletions pkg/labeler/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,58 +238,3 @@ func TestLabelRemote(t *testing.T) {
})
}
}

func TestGetCloudRegions(t *testing.T) {
// Assert we found all regions we deploy to at the time of test
// implementation (2024-09-05).
aws, gcp, _, azure, err := getCloudRanges()
assert.NoError(t, err)

regions, err := getCloudRegions(AWS, aws)
assert.NoError(t, err)
assert.NotNil(t, regions)
assert.Contains(t, regions, "us-west-2")
assert.Contains(t, regions, "us-east-2")
assert.Contains(t, regions, "eu-west-1")
assert.Contains(t, regions, "af-south-1")
assert.Contains(t, regions, "ap-northeast-1")
assert.Contains(t, regions, "ap-south-1")
assert.Contains(t, regions, "ap-southeast-1")
assert.Contains(t, regions, "ca-central-1")
assert.Contains(t, regions, "eu-central-1")
assert.Contains(t, regions, "eu-north-1")
assert.Contains(t, regions, "eu-west-2")
assert.Contains(t, regions, "us-east-1")

regions, err = getCloudRegions(GCP, gcp)
assert.NoError(t, err)
assert.NotNil(t, regions)
assert.Contains(t, regions, "asia-northeast1")
assert.Contains(t, regions, "asia-southeast1")
assert.Contains(t, regions, "us-east1")
assert.Contains(t, regions, "europe-west3")
assert.Contains(t, regions, "europe-west4")
assert.Contains(t, regions, "europe-west6")
assert.Contains(t, regions, "australia-southeast1")
assert.Contains(t, regions, "northamerica-northeast1")
assert.Contains(t, regions, "us-central1")
assert.Contains(t, regions, "us-west1")

regions, err = getCloudRegions(Azure, azure)
assert.NoError(t, err)
assert.NotNil(t, regions)
assert.Contains(t, regions, "westus3")
assert.Contains(t, regions, "eastus2")
assert.Contains(t, regions, "germanywc")
assert.Contains(t, regions, "eastus")
}

func TestTryGetHostIPs(t *testing.T) {
ips, err := tryGetHostIPs("ilyadoesnotexist.ilya")
assert.NoError(t, err)
assert.Nil(t, ips)

ips, err = tryGetHostIPs("clickhouse.cloud")
assert.NoError(t, err)
assert.NotNil(t, ips)
}

0 comments on commit b2c2f28

Please sign in to comment.