diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..a3ffac2 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -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 diff --git a/.github/workflows/kubenetmon.yaml b/.github/workflows/kubenetmon.yaml index 186184c..f9e9350 100644 --- a/.github/workflows/kubenetmon.yaml +++ b/.github/workflows/kubenetmon.yaml @@ -1,4 +1,4 @@ -name: CI Workflow +name: Main workflow on: pull_request: @@ -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 @@ -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 diff --git a/Makefile b/Makefile index a841bb7..e03cbe1 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pkg/labeler/labeler.go b/pkg/labeler/labeler.go index 80011f3..88a03ad 100644 --- a/pkg/labeler/labeler.go +++ b/pkg/labeler/labeler.go @@ -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). diff --git a/pkg/labeler/remote.go b/pkg/labeler/remote.go index 79c47ad..1962465 100644 --- a/pkg/labeler/remote.go +++ b/pkg/labeler/remote.go @@ -2,7 +2,6 @@ package labeler import ( "fmt" - "net" "sync" "time" @@ -32,11 +31,6 @@ type RemoteLabeler struct { cloud Cloud } -type azDetail struct { - region string - azID string -} - var ( publicIPRefreshCounter = promauto.NewCounterVec( prometheus.CounterOpts{ @@ -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 -} diff --git a/pkg/labeler/remote_test.go b/pkg/labeler/remote_test.go index 67ef59c..e12c879 100644 --- a/pkg/labeler/remote_test.go +++ b/pkg/labeler/remote_test.go @@ -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) -}