Skip to content

Commit

Permalink
feat: Bump lowest supported k8s version to 1.23 (#2162)
Browse files Browse the repository at this point in the history
* feat: Bump lowest supported k8s version to 1.23

Signed-off-by: Jorge Turrado <[email protected]>

* u8ndo the format

Signed-off-by: Jorge Turrado <[email protected]>

* undo wrong change

Signed-off-by: Jorge Turrado <[email protected]>

* update kind-yaml

Signed-off-by: Jorge Turrado <[email protected]>

* unify stykle

Signed-off-by: Jorge Turrado <[email protected]>

* revert the change

* apply feedback

Signed-off-by: Jorge Turrado <[email protected]>

* apply feedback

Signed-off-by: Jorge Turrado <[email protected]>

* apply feedback

Signed-off-by: Jorge Turrado <[email protected]>

---------

Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer authored Sep 28, 2023
1 parent 29e8ba3 commit 37cf662
Show file tree
Hide file tree
Showing 32 changed files with 277 additions and 1,057 deletions.
20 changes: 20 additions & 0 deletions .chloggen/get-rid-of-autoscaling-v2beta2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Get rid of autoscaling/v2beta2

# One or more tracking issues related to the change
issues:
- 2145

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Kubernetes 1.23 is the minimum available version everywhere after 1.22 deprecation,
due to it, the minimum required version has been updated to it, dropping support for
autoscaling/v2beta2
8 changes: 2 additions & 6 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
CURRENT_KIND_VERSION: 0.20.0
LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore

jobs:
e2e-tests:
name: End-to-end tests
Expand All @@ -25,7 +21,7 @@ jobs:
# All Kubernetes version in between expose the same APIs, hence the operator
# should be compatible with them.
kube-version:
- "1.19"
- "1.23"
- "1.28"
group:
- e2e
Expand All @@ -42,7 +38,7 @@ jobs:

- name: Setup kind
env:
KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }}
KIND_VERSION: "0.20.0"
run: go install sigs.k8s.io/kind@v${KIND_VERSION}

- name: Check out code into the Go module directory
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/scorecard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
CURRENT_KIND_VERSION: 0.20.0
LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore

jobs:
scorecard-tests:
name: test on k8s
runs-on: ubuntu-22.04
strategy:
matrix:
kube-version:
- "1.19"
- "1.23"
- "1.28"

steps:
Expand All @@ -33,7 +29,7 @@ jobs:

- name: Setup kind
env:
KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }}
KIND_VERSION: "0.20.0"
run: go install sigs.k8s.io/kind@v${KIND_VERSION}

- name: Check out code into the Go module directory
Expand Down
8 changes: 1 addition & 7 deletions controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -304,12 +303,7 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er
builder.Owns(&monitoringv1.ServiceMonitor{})
}

autoscalingVersion := r.config.AutoscalingVersion()
if autoscalingVersion == autodetect.AutoscalingVersionV2 {
builder = builder.Owns(&autoscalingv2.HorizontalPodAutoscaler{})
} else {
builder = builder.Owns(&autoscalingv2beta2.HorizontalPodAutoscaler{})
}
builder = builder.Owns(&autoscalingv2.HorizontalPodAutoscaler{})

return builder.Complete(r)
}
8 changes: 0 additions & 8 deletions controllers/opentelemetrycollector_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ import (

var logger = logf.Log.WithName("unit-tests")
var mockAutoDetector = &mockAutoDetect{
HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) {
return autodetect.AutoscalingVersionV2Beta2, nil
},
OpenShiftRoutesAvailabilityFunc: func() (autodetect.OpenShiftRoutesAvailability, error) {
return autodetect.OpenShiftRoutesAvailable, nil
},
Expand Down Expand Up @@ -336,11 +333,6 @@ var _ autodetect.AutoDetect = (*mockAutoDetect)(nil)

type mockAutoDetect struct {
OpenShiftRoutesAvailabilityFunc func() (autodetect.OpenShiftRoutesAvailability, error)
HPAVersionFunc func() (autodetect.AutoscalingVersion, error)
}

func (m *mockAutoDetect) HPAVersion() (autodetect.AutoscalingVersion, error) {
return m.HPAVersionFunc()
}

func (m *mockAutoDetect) OpenShiftRoutesAvailability() (autodetect.OpenShiftRoutesAvailability, error) {
Expand Down
48 changes: 2 additions & 46 deletions controllers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
"github.com/open-telemetry/opentelemetry-operator/pkg/autodetect"
)

const (
Expand Down Expand Up @@ -276,54 +275,11 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
},
},
},
{
name: "hpa v2beta2 deployment collector",
args: args{
params: paramsWithHPA(autodetect.AutoscalingVersionV2Beta2, 3, 5),
updates: []manifests.Params{paramsWithHPA(autodetect.AutoscalingVersionV2Beta2, 1, 9)},
},
want: []want{
{
result: controllerruntime.Result{},
checks: []check{
func(t *testing.T, appliedInstance v1alpha1.OpenTelemetryCollector) {
actual := autoscalingv2beta2.HorizontalPodAutoscaler{}
exists, hpaErr := populateObjectIfExists(t, &actual, namespacedObjectName(appliedInstance, naming.HorizontalPodAutoscaler))
assert.NoError(t, hpaErr)
require.Len(t, actual.Spec.Metrics, 1)
assert.Equal(t, int32(90), *actual.Spec.Metrics[0].Resource.Target.AverageUtilization)
assert.Equal(t, int32(3), *actual.Spec.MinReplicas)
assert.Equal(t, int32(5), actual.Spec.MaxReplicas)
assert.True(t, exists)
},
},
wantErr: assert.NoError,
validateErr: assert.NoError,
},
{
result: controllerruntime.Result{},
checks: []check{
func(t *testing.T, appliedInstance v1alpha1.OpenTelemetryCollector) {
actual := autoscalingv2beta2.HorizontalPodAutoscaler{}
exists, hpaErr := populateObjectIfExists(t, &actual, namespacedObjectName(appliedInstance, naming.HorizontalPodAutoscaler))
assert.NoError(t, hpaErr)
require.Len(t, actual.Spec.Metrics, 1)
assert.Equal(t, int32(90), *actual.Spec.Metrics[0].Resource.Target.AverageUtilization)
assert.Equal(t, int32(1), *actual.Spec.MinReplicas)
assert.Equal(t, int32(9), actual.Spec.MaxReplicas)
assert.True(t, exists)
},
},
wantErr: assert.NoError,
validateErr: assert.NoError,
},
},
},
{
name: "hpa v2 deployment collector",
args: args{
params: paramsWithHPA(autodetect.AutoscalingVersionV2, 3, 5),
updates: []manifests.Params{paramsWithHPA(autodetect.AutoscalingVersionV2, 1, 9)},
params: paramsWithHPA(3, 5),
updates: []manifests.Params{paramsWithHPA(1, 9)},
},
want: []want{
{
Expand Down
14 changes: 2 additions & 12 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
"github.com/open-telemetry/opentelemetry-operator/internal/config"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/testdata"
"github.com/open-telemetry/opentelemetry-operator/pkg/autodetect"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -277,24 +276,15 @@ func newParams(taContainerImage string, file string) (manifests.Params, error) {
}, nil
}

func paramsWithHPA(autoscalingVersion autodetect.AutoscalingVersion, minReps, maxReps int32) manifests.Params {
func paramsWithHPA(minReps, maxReps int32) manifests.Params {
configYAML, err := os.ReadFile("testdata/test.yaml")
if err != nil {
fmt.Printf("Error getting yaml file: %v", err)
}

cpuUtilization := int32(90)

mockAutoDetector := &mockAutoDetect{
HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) {
return autoscalingVersion, nil
},
}
configuration := config.New(config.WithAutoDetect(mockAutoDetector), config.WithCollectorImage(defaultCollectorImage), config.WithTargetAllocatorImage(defaultTaAllocationImage))
err = configuration.AutoDetect()
if err != nil {
logger.Error(err, "configuration.autodetect failed")
}
configuration := config.New(config.WithCollectorImage(defaultCollectorImage), config.WithTargetAllocatorImage(defaultTaAllocationImage))

return manifests.Params{
Config: configuration,
Expand Down
46 changes: 0 additions & 46 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Config struct {
labelsFilter []string
openshiftRoutes openshiftRoutesStore
autoDetectFrequency time.Duration
hpaVersion hpaVersionStore
}

// New constructs a new configuration based on the given options.
Expand All @@ -63,7 +62,6 @@ func New(opts ...Option) Config {
targetAllocatorConfigMapEntry: defaultTargetAllocatorConfigMapEntry,
logger: logf.Log.WithName("config"),
openshiftRoutes: newOpenShiftRoutesWrapper(),
hpaVersion: newHPAVersionWrapper(),
version: version.Get(),
onOpenShiftRoutesChange: newOnChange(),
}
Expand All @@ -81,7 +79,6 @@ func New(opts ...Option) Config {
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
logger: o.logger,
openshiftRoutes: o.openshiftRoutes,
hpaVersion: o.hpaVersion,
onOpenShiftRoutesChange: o.onOpenShiftRoutesChange,
autoInstrumentationJavaImage: o.autoInstrumentationJavaImage,
autoInstrumentationNodeJSImage: o.autoInstrumentationNodeJSImage,
Expand Down Expand Up @@ -129,15 +126,6 @@ func (c *Config) AutoDetect() error {
}
}

hpaV, err := c.autoDetect.HPAVersion()
if err != nil {
return err
}
if c.hpaVersion.Get() != hpaV {
c.logger.V(1).Info("HPA version detected", "version", hpaV)
c.hpaVersion.Set(hpaV)
}

return nil
}

Expand Down Expand Up @@ -166,11 +154,6 @@ func (c *Config) OpenShiftRoutes() autodetect.OpenShiftRoutesAvailability {
return c.openshiftRoutes.Get()
}

// AutoscalingVersion represents the preferred version of autoscaling.
func (c *Config) AutoscalingVersion() autodetect.AutoscalingVersion {
return c.hpaVersion.Get()
}

// AutoInstrumentationJavaImage returns OpenTelemetry Java auto-instrumentation container image.
func (c *Config) AutoInstrumentationJavaImage() string {
return c.autoInstrumentationJavaImage
Expand Down Expand Up @@ -212,35 +195,6 @@ func (c *Config) RegisterOpenShiftRoutesChangeCallback(f func() error) {
c.onOpenShiftRoutesChange.Register(f)
}

type hpaVersionStore interface {
Set(hpaV autodetect.AutoscalingVersion)
Get() autodetect.AutoscalingVersion
}

func newHPAVersionWrapper() hpaVersionStore {
return &hpaVersionWrapper{
current: autodetect.AutoscalingVersionUnknown,
}
}

type hpaVersionWrapper struct {
mu sync.Mutex
current autodetect.AutoscalingVersion
}

func (p *hpaVersionWrapper) Set(hpaV autodetect.AutoscalingVersion) {
p.mu.Lock()
p.current = hpaV
p.mu.Unlock()
}

func (p *hpaVersionWrapper) Get() autodetect.AutoscalingVersion {
p.mu.Lock()
hpaV := p.current
p.mu.Unlock()
return hpaV
}

type openshiftRoutesStore interface {
Set(ora autodetect.OpenShiftRoutesAvailability)
Get() autodetect.OpenShiftRoutesAvailability
Expand Down
14 changes: 0 additions & 14 deletions internal/config/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestNewConfig(t *testing.T) {
assert.Equal(t, "some-image", cfg.CollectorImage())
assert.Equal(t, "some-config.yaml", cfg.CollectorConfigMapEntry())
assert.Equal(t, autodetect.OpenShiftRoutesNotAvailable, cfg.OpenShiftRoutes())
assert.Equal(t, autodetect.AutoscalingVersionUnknown, cfg.AutoscalingVersion())
}

func TestOnPlatformChangeCallback(t *testing.T) {
Expand Down Expand Up @@ -78,10 +77,6 @@ func TestAutoDetectInBackground(t *testing.T) {
wg.Done()
return autodetect.OpenShiftRoutesNotAvailable, nil
},
HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) {
wg.Done()
return autodetect.AutoscalingVersionV2, nil
},
}
cfg := config.New(
config.WithAutoDetect(mock),
Expand All @@ -90,7 +85,6 @@ func TestAutoDetectInBackground(t *testing.T) {

// sanity check
require.Equal(t, autodetect.OpenShiftRoutesNotAvailable, cfg.OpenShiftRoutes())
require.Equal(t, autodetect.AutoscalingVersionUnknown, cfg.AutoscalingVersion())

// test
err := cfg.StartAutoDetect()
Expand All @@ -104,14 +98,6 @@ var _ autodetect.AutoDetect = (*mockAutoDetect)(nil)

type mockAutoDetect struct {
OpenShiftRoutesAvailabilityFunc func() (autodetect.OpenShiftRoutesAvailability, error)
HPAVersionFunc func() (autodetect.AutoscalingVersion, error)
}

func (m *mockAutoDetect) HPAVersion() (autodetect.AutoscalingVersion, error) {
if m.HPAVersionFunc != nil {
return m.HPAVersionFunc()
}
return autodetect.DefaultAutoscalingVersion, nil
}

func (m *mockAutoDetect) OpenShiftRoutesAvailability() (autodetect.OpenShiftRoutesAvailability, error) {
Expand Down
1 change: 0 additions & 1 deletion internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type options struct {
onOpenShiftRoutesChange changeHandler
labelsFilter []string
openshiftRoutes openshiftRoutesStore
hpaVersion hpaVersionStore
autoDetectFrequency time.Duration
}

Expand Down
Loading

0 comments on commit 37cf662

Please sign in to comment.