Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/hack/generators/github…
Browse files Browse the repository at this point in the history
….com/samber/lo-1.44.0
  • Loading branch information
pmalek authored Jul 3, 2024
2 parents 83cfe1f + ceda2db commit cbae44c
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/__build-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:

- name: Build image
id: build
uses: docker/build-push-action@v6.2.0
uses: docker/build-push-action@v6.3.0
with:
context: .
build-contexts: ${{ inputs.additional-build-contexts }}
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
- [v0.1.1](#v011)
- [v0.1.0](#v010)

## Unreleased

> Release date: TBD
### Added

- Proper `User-Agent` header is now set on outgoing HTTP requests.
[#387](https://github.com/Kong/gateway-operator/pull/387)

## [v1.3.0]

> Release date: 2024-06-24
Expand Down
2 changes: 1 addition & 1 deletion config/samples/controlplane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
containers:
- name: controller
# renovate: datasource=docker versioning=docker
image: kong/kubernetes-ingress-controller:3.2.1
image: kong/kubernetes-ingress-controller:3.2.2
readinessProbe:
initialDelaySeconds: 1
periodSeconds: 3
Expand Down
2 changes: 1 addition & 1 deletion config/samples/gateway-httproute-allowedroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec:
containers:
- name: controller
# renovate: datasource=docker versioning=docker
image: kong/kubernetes-ingress-controller:3.2.1
image: kong/kubernetes-ingress-controller:3.2.2
readinessProbe:
initialDelaySeconds: 1
periodSeconds: 1
Expand Down
2 changes: 1 addition & 1 deletion config/samples/gateway-httproute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ spec:
containers:
- name: controller
# renovate: datasource=docker versioning=docker
image: kong/kubernetes-ingress-controller:3.2.1
image: kong/kubernetes-ingress-controller:3.2.2
readinessProbe:
initialDelaySeconds: 1
periodSeconds: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ spec:
containers:
- name: controller
# renovate: datasource=docker versioning=docker
image: kong/kubernetes-ingress-controller:3.2.1
image: kong/kubernetes-ingress-controller:3.2.2
readinessProbe:
initialDelaySeconds: 1
periodSeconds: 1
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/cloudflare/cfssl v1.6.5
github.com/go-logr/logr v1.4.2
github.com/google/uuid v1.6.0
github.com/kong/kubernetes-ingress-controller/v3 v3.2.1
github.com/kong/kubernetes-ingress-controller/v3 v3.2.2
github.com/kong/kubernetes-telemetry v0.1.4
github.com/kong/kubernetes-testing-framework v0.47.1
github.com/kong/semver/v4 v4.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kong/go-kong v0.56.0 h1:/9qbnQJWAgrSAKzL2RViBhHMTYOEyG8N4ClkKnUwEW4=
github.com/kong/go-kong v0.56.0/go.mod h1:gyNwyP1fzztT6sX/0/ygMQ30OiRMIQ51b2jSfstMrcU=
github.com/kong/kubernetes-ingress-controller/v3 v3.2.1 h1:0JC1Sm6KLdCtC9YvYs+c0AySNvEyd3l16NGZWm1MU04=
github.com/kong/kubernetes-ingress-controller/v3 v3.2.1/go.mod h1:gshVZnDU2FTe/95I3vSJPsH2kyB8zR+GpUIieCyt8C4=
github.com/kong/kubernetes-ingress-controller/v3 v3.2.2 h1:2lFP0AanAfdEQ2XNQwSxR4BP5lpy/BAmNqIxp953qe0=
github.com/kong/kubernetes-ingress-controller/v3 v3.2.2/go.mod h1:gshVZnDU2FTe/95I3vSJPsH2kyB8zR+GpUIieCyt8C4=
github.com/kong/kubernetes-telemetry v0.1.4 h1:Yz7OlECxWKgNRG1wJ5imA4+H0dQEpdU9d86uhwUVpu4=
github.com/kong/kubernetes-telemetry v0.1.4/go.mod h1:z3yB5naZjUmQCFjzD3hsJ9PVYar7BgPJFKzskUuOejU=
github.com/kong/kubernetes-testing-framework v0.47.1 h1:BE2mQLC0Zj/NC5Y8B1Nm5VZymmrdVfu7cfwVKSobWtg=
Expand Down
2 changes: 1 addition & 1 deletion internal/versions/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
// and those tests create KIC's URLs for things like roles or CRDs.
// Since KIC only defines the full tags in its repo (as expected) we cannot use
// a partial version here, as it would not match KIC's tag.
DefaultControlPlaneVersion = "3.2.1" // renovate: datasource=docker depName=kong/kubernetes-ingress-controller
DefaultControlPlaneVersion = "3.2.2" // renovate: datasource=docker depName=kong/kubernetes-ingress-controller
)

// minimumControlPlaneVersion indicates the bare minimum version of the
Expand Down
29 changes: 24 additions & 5 deletions modules/manager/metadata/metadata.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
// Package metadata includes metadata variables for logging and reporting.
package metadata

import (
"fmt"
"runtime"
)

// -----------------------------------------------------------------------------
// Controller Manager - Versioning Information
// -----------------------------------------------------------------------------

// WARNING: moving any of these variables requires changes to both the Makefile
// and the Dockerfile which modify them during the link step with -X

// BuildFlavor is the flavor of the build.
type BuildFlavor string

const (
// OSSFlavor is the open-source flavor.
OSSFlavor BuildFlavor = "oss"
// EEFlavor is the enterprise flavor.
EEFlavor BuildFlavor = "enterprise"
)

// Info is a struct type that holds the metadata for the controller manager.
type Info struct {
// Release returns the release version, generally a semver like v1.0.0.
Expand All @@ -29,7 +44,14 @@ type Info struct {
Organization string

// Flavor is the flavor of the build.
Flavor string
Flavor BuildFlavor
}

// UserAgent returns the User-Agent string to use in all HTTP requests made by KGO.
func (inf Info) UserAgent() string {
return fmt.Sprintf("%s/%s (%s/%s) (%s)",
inf.ProjectName, inf.Release, runtime.GOOS, runtime.GOARCH, inf.Flavor,
)
}

var (
Expand All @@ -50,9 +72,6 @@ var (

// Organization is the Kong organization
organization = "Kong"

// Flavor is the flavor of the build.
flavor = "oss"
)

// Metadata returns the metadata for the controller manager.
Expand All @@ -64,6 +83,6 @@ func Metadata() Info {
Commit: commit,
ProjectName: projectName,
Organization: organization,
Flavor: flavor,
Flavor: OSSFlavor,
}
}
30 changes: 8 additions & 22 deletions modules/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand Down Expand Up @@ -82,7 +81,7 @@ type Config struct {
DataPlaneControllerEnabled bool
DataPlaneBlueGreenControllerEnabled bool

// Controllers for speciality APIs and experimental features.
// Controllers for specialty APIs and experimental features.
AIGatewayControllerEnabled bool

// webhook and validation options
Expand Down Expand Up @@ -156,7 +155,10 @@ func Run(
setupLog.Info("leader election disabled")
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
restCfg := ctrl.GetConfigOrDie()
restCfg.UserAgent = metadata.UserAgent()

mgr, err := ctrl.NewManager(restCfg, ctrl.Options{
Scheme: scheme,
Metrics: server.Options{
BindAddress: cfg.MetricsAddr,
Expand Down Expand Up @@ -244,7 +246,7 @@ func Run(
// Enable anonnymous reporting when configured but not for development builds
// to reduce the noise.
if cfg.AnonymousReports && !cfg.DevelopmentMode {
stopAnonymousReports, err := setupAnonymousReports(context.Background(), cfg, setupLog, metadata)
stopAnonymousReports, err := setupAnonymousReports(context.Background(), restCfg, setupLog, metadata)
if err != nil {
setupLog.Error(err, "failed setting up anonymous reports")
} else {
Expand Down Expand Up @@ -353,35 +355,19 @@ func (m *caManager) maybeCreateCACertificate(ctx context.Context) error {
return nil
}

func getKubeconfig(apiServerPath string, kubeconfig string) (*rest.Config, error) {
config, err := clientcmd.BuildConfigFromFlags(apiServerPath, kubeconfig)
if err != nil {
// Fall back to default client loading rules.
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
// if you want to change the loading rules (which files in which order), you can do so here
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, nil)
return kubeConfig.ClientConfig()
}
return config, nil
}

// setupAnonymousReports sets up and starts the anonymous reporting and returns
// a cleanup function and an error.
// The caller is responsible to call the returned function - when the returned
// error is not nil - to stop the reports sending.
func setupAnonymousReports(ctx context.Context, cfg Config, logger logr.Logger, metadata metadata.Info) (func(), error) {
func setupAnonymousReports(ctx context.Context, restCfg *rest.Config, logger logr.Logger, metadata metadata.Info) (func(), error) {
logger.Info("starting anonymous reports")
restConfig, err := getKubeconfig(cfg.APIServerPath, cfg.KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to get kubeconfig: %w", err)
}

payload := telemetry.Payload{
"v": metadata.Release,
"flavor": metadata.Flavor,
}

tMgr, err := telemetry.CreateManager(telemetry.SignalPing, restConfig, logger, payload)
tMgr, err := telemetry.CreateManager(telemetry.SignalPing, restCfg, logger, payload)
if err != nil {
return nil, fmt.Errorf("failed to create anonymous reports manager: %w", err)
}
Expand Down

0 comments on commit cbae44c

Please sign in to comment.