Skip to content

Commit

Permalink
changes after merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
olavangad-px committed Jan 24, 2024
1 parent e16568c commit 2994e09
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 42 deletions.
131 changes: 89 additions & 42 deletions pkg/controller/storagecluster/stork.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/hashicorp/go-version"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -53,6 +54,9 @@ const (
// K8S scheduler policy decoder changed in this version.
// https://github.com/kubernetes/kubernetes/blob/release-1.21/pkg/scheduler/scheduler.go#L306
policyDecoderChangeVersion = "1.17.0"
// kubescheduler.config.k8s.io/v1 is GA'ed only in k8s 1.25
// so for 1.23 <= ver < 1.25 we should continue using kubescheduler.config.k8s.io/v1beta3
minK8sVersionForKubeSchedulerV1Configuration = "1.25.0"
)

const (
Expand Down Expand Up @@ -234,56 +238,99 @@ func (c *Controller) createStorkConfigMap(
clusterNamespace string,
ownerRef *metav1.OwnerReference,
) error {

// KubeSchedulerConfiguration is beta in 1.23 and GA in 1.25
k8sMinVersionForKubeSchedulerV1Configuration, err := version.NewVersion(minK8sVersionForKubeSchedulerV1Configuration)
if err != nil {
logrus.WithError(err).Errorf("Could not parse version %s", k8sMinVersionForKubeSchedulerV1Configuration)
return err

Check warning on line 245 in pkg/controller/storagecluster/stork.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/storagecluster/stork.go#L244-L245

Added lines #L244 - L245 were not covered by tests
}

leaderElect := true
schedulerName := storkDeploymentName
kubeSchedulerConfiguration := schedconfig.KubeSchedulerConfiguration{
TypeMeta: metav1.TypeMeta{
Kind: "KubeSchedulerConfiguration",
APIVersion: "kubescheduler.config.k8s.io/v1beta3",
},
LeaderElection: schedcomp.LeaderElectionConfiguration{
LeaderElect: &leaderElect,
ResourceNamespace: clusterNamespace,
ResourceName: storkSchedDeploymentName,
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
ResourceLock: "leases",
},
Profiles: []schedconfig.KubeSchedulerProfile{
{
SchedulerName: &schedulerName,
},
},
Extenders: []schedconfig.Extender{
{
URLPrefix: fmt.Sprintf(
"http://%s.%s:%d",
storkServiceName, clusterNamespace, storkServicePort,
),
FilterVerb: "filter",
PrioritizeVerb: "prioritize",
Weight: 5,
EnableHTTPS: false,
NodeCacheCapable: false,
HTTPTimeout: metav1.Duration{Duration: 5 * time.Minute},
},
},
leaderElectionConfiguration := schedcomp.LeaderElectionConfiguration{
LeaderElect: &leaderElect,
ResourceNamespace: clusterNamespace,
ResourceName: storkSchedDeploymentName,
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
ResourceLock: "leases",
}

// Auto fill the default configuration params
schedconfigapi.SetDefaults_KubeSchedulerConfiguration(&kubeSchedulerConfiguration)

var policyConfig []byte
var dataKey string
var err error
if c.kubernetesVersion.GreaterThanOrEqual(k8sutil.MinVersionForKubeSchedulerConfiguration) {
policyConfig, err = yaml.Marshal(kubeSchedulerConfiguration)
if err != nil {
logrus.WithError(err).Errorf("Could not encode policy object")
return err
if c.kubernetesVersion.GreaterThanOrEqual(k8sMinVersionForKubeSchedulerV1Configuration) {
// enter this branch when k8s ver >= 1.25
kubeSchedulerConfigurationV1 := schedconfig.KubeSchedulerConfiguration{
TypeMeta: metav1.TypeMeta{
Kind: "KubeSchedulerConfiguration",
APIVersion: "kubescheduler.config.k8s.io/v1",
},
LeaderElection: leaderElectionConfiguration,
Profiles: []schedconfig.KubeSchedulerProfile{
{
SchedulerName: &schedulerName,
},
},
Extenders: []schedconfig.Extender{
{
URLPrefix: fmt.Sprintf(
"http://%s.%s:%d",
storkServiceName, clusterNamespace, storkServicePort,
),
FilterVerb: "filter",
PrioritizeVerb: "prioritize",
Weight: 5,
EnableHTTPS: false,
NodeCacheCapable: false,
HTTPTimeout: metav1.Duration{Duration: 5 * time.Minute},
},
},
}
// Auto fill the default configuration params
schedconfigapi.SetDefaults_KubeSchedulerConfiguration(&kubeSchedulerConfigurationV1)
policyConfig, err = yaml.Marshal(kubeSchedulerConfigurationV1)
if err != nil {
logrus.WithError(err).Errorf("Could not encode policy object")
return err

Check warning on line 296 in pkg/controller/storagecluster/stork.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/storagecluster/stork.go#L295-L296

Added lines #L295 - L296 were not covered by tests
}
} else {
// enter this branch when 1.23 <= k8s ver < 1.25
kubeSchedulerConfigurationV1Beta := schedconfigbeta3.KubeSchedulerConfiguration{
TypeMeta: metav1.TypeMeta{
Kind: "KubeSchedulerConfiguration",
APIVersion: "kubescheduler.config.k8s.io/v1beta3",
},
LeaderElection: leaderElectionConfiguration,
Profiles: []schedconfigbeta3.KubeSchedulerProfile{
{
SchedulerName: &schedulerName,
},
},
Extenders: []schedconfigbeta3.Extender{
{
URLPrefix: fmt.Sprintf(
"http://%s.%s:%d",
storkServiceName, clusterNamespace, storkServicePort,
),
FilterVerb: "filter",
PrioritizeVerb: "prioritize",
Weight: 5,
EnableHTTPS: false,
NodeCacheCapable: false,
HTTPTimeout: metav1.Duration{Duration: 5 * time.Minute},
},
},
}

// Auto fill the default configuration params
schedconfigapibeta3.SetDefaults_KubeSchedulerConfiguration(&kubeSchedulerConfigurationV1Beta)
policyConfig, err = yaml.Marshal(kubeSchedulerConfigurationV1Beta)
if err != nil {
logrus.WithError(err).Errorf("Could not encode policy object")
return err

Check warning on line 332 in pkg/controller/storagecluster/stork.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/storagecluster/stork.go#L331-L332

Added lines #L331 - L332 were not covered by tests
}
}
dataKey = "stork-config.yaml"
} else {
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/storagecluster/stork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func testStorkInstallation(t *testing.T, k8sVersionStr string) {
require.Equal(t, cluster.Namespace, storkConfigMap.Namespace)
require.Len(t, storkConfigMap.OwnerReferences, 1)
require.Equal(t, cluster.Name, storkConfigMap.OwnerReferences[0].Name)
k8sMinVersionForKubeSchedulerV1Configuration, err := version.NewVersion(minK8sVersionForKubeSchedulerV1Configuration)
require.NoError(t, err)

if k8sVersion.GreaterThanOrEqual(k8sMinVersionForKubeSchedulerV1Configuration) {
expectedKubeSchedulerConfiguration := schedconfig.KubeSchedulerConfiguration{
Expand Down

0 comments on commit 2994e09

Please sign in to comment.