8000 [Feature] [Scheduler] SchedV1 Integration by ajanikow · Pull Request #1732 · arangodb/kube-arangodb · GitHub
[go: up one dir, main page]

Skip to content

[Feature] [Scheduler] SchedV1 Integration #1732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- (Feature) (Scheduler) Create Integration Profile
- (Feature) (Scheduler) Additional types
- (Feature) Alternative Upgrade Order Feature
- (Feature) (Scheduler) SchedV1 Integration

## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries
Expand Down
20 changes: 20 additions & 0 deletions pkg/debug_package/generators/kubernetes/arango_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,25 @@ func scheduler(logger zerolog.Logger, files chan<- shared.File) error {
return err
}

if err := schedulerPods(logger, files, k); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
return err
}

if err := schedulerDeployments(logger, files, k); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
return err
}

if err := schedulerBatchJobs(logger, files, k); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
return err
}

if err := schedulerCronJobs(logger, files, k); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
return err
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package kubernetes

import (
"context"
"fmt"

"github.com/rs/zerolog"

schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)

func schedulerBatchJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
batchjobs, err := listSchedulerBatchJobs(client)
if err != nil {
if kerrors.IsForbiddenOrNotFound(err) {
return nil
}

return err
}

if err := errors.ExecuteWithErrorArrayP2(schedulerBatchJob, client, files, batchjobs...); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler batchjobs")
return err
}

return nil
}

func schedulerBatchJob(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerBatchJob) error {
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerbatchjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
return []interface{}{ext}, nil
})

return nil
}

func listSchedulerBatchJobs(client kclient.Client) ([]*schedulerApi.ArangoSchedulerBatchJob, error) {
return ListObjects[*schedulerApi.ArangoSchedulerBatchJobList, *schedulerApi.ArangoSchedulerBatchJob](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerBatchJobs(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerBatchJobList) []*schedulerApi.ArangoSchedulerBatchJob {
q := make([]*schedulerApi.ArangoSchedulerBatchJob, len(result.Items))

for id, e := range result.Items {
q[id] = e.DeepCopy()
}

return q
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package kubernetes

import (
"context"
"fmt"

"github.com/rs/zerolog"

schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)

func schedulerCronJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
cronjobs, err := listSchedulerCronJobs(client)
if err != nil {
if kerrors.IsForbiddenOrNotFound(err) {
return nil
}

return err
}

if err := errors.ExecuteWithErrorArrayP2(schedulerCronJob, client, files, cronjobs...); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler cronjobs")
return err
}

return nil
}

func schedulerCronJob(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerCronJob) error {
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulercronjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
return []interface{}{ext}, nil
})

return nil
}

func listSchedulerCronJobs(client kclient.Client) ([]*schedulerApi.ArangoSchedulerCronJob, error) {
return ListObjects[*schedulerApi.ArangoSchedulerCronJobList, *schedulerApi.ArangoSchedulerCronJob](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerCronJobs(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerCronJobList) []*schedulerApi.ArangoSchedulerCronJob {
q := make([]*schedulerApi.ArangoSchedulerCronJob, len(result.Items))

for id, e := range result.Items {
q[id] = e.DeepCopy()
}

return q
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package kubernetes

import (
"context"
"fmt"

"github.com/rs/zerolog"

schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)

func schedulerDeployments(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) err 9E88 or {
deployments, err := listSchedulerDeployments(client)
if err != nil {
if kerrors.IsForbiddenOrNotFound(err) {
return nil
}

return err
}

if err := errors.ExecuteWithErrorArrayP2(schedulerDeployment, client, files, deployments...); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler deployments")
return err
}

return nil
}

func schedulerDeployment(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerDeployment) error {
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerdeployments/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
return []interface{}{ext}, nil
})

return nil
}

func listSchedulerDeployments(client kclient.Client) ([]*schedulerApi.ArangoSchedulerDeployment, error) {
return ListObjects[*schedulerApi.ArangoSchedulerDeploymentList, *schedulerApi.ArangoSchedulerDeployment](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerDeployments(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerDeploymentList) []*schedulerApi.ArangoSchedulerDeployment {
q := make([]*schedulerApi.ArangoSchedulerDeployment, len(result.Items))

for id, e := range result.Items {
q[id] = e.DeepCopy()
}

return q
})
}
73 changes: 73 additions & 0 deletions pkg/debug_package/generators/kubernetes/arango_scheduler_pod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package kubernetes

import (
"context"
"fmt"

"github.com/rs/zerolog"

schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)

func schedulerPods(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
pods, err := listSchedulerPods(client)
if err != nil {
if kerrors.IsForbiddenOrNotFound(err) {
return nil
}

return err
}

if err := errors.ExecuteWithErrorArrayP2(schedulerPod, client, files, pods...); err != nil {
logger.Err(err).Msgf("Error while collecting arango scheduler pods")
return err
}

return nil
}

func schedulerPod(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerPod) error {
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerpods/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
return []interface{}{ext}, nil
})

return nil
}

func listSchedulerPods(client kclient.Client) ([]*schedulerApi.ArangoSchedulerPod, error) {
return ListObjects[*schedulerApi.ArangoSchedulerPodList, *schedulerApi.ArangoSchedulerPod](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerPods(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerPodList) []*schedulerApi.ArangoSchedulerPod {
q := make([]*schedulerApi.ArangoSchedulerPod, len(result.Items))

for id, e := range result.Items {
q[id] = e.DeepCopy()
}

return q
})
}
11 changes: 7 additions & 4 deletions pkg/deployment/resources/arango_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
return "", nil, err
}

key, v := constants.NewProfileIntegration(name, version)

return fullName, &schedulerApi.ArangoProfile{
ObjectMeta: meta.ObjectMeta{
Name: fullName,
Expand All @@ -91,8 +93,8 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
},
Spec: schedulerApi.ProfileSpec{
Selectors: matchArangoProfilesLabels(map[string]string{
constants.ProfilesDeployment: deploymentName,
fmt.Sprintf("%s/%s", constants.ProfilesIntegrationPrefix, name): version,
constants.ProfilesDeployment: deploymentName,
key: v,
}),
Template: integration,
},
Expand Down Expand Up @@ -128,8 +130,9 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
},
}, nil
},
gen("authz", "v0", sidecar.IntegrationAuthorizationV0{}),
gen("authn", "v1", sidecar.IntegrationAuthenticationV1{Spec: spec, DeploymentName: apiObject.GetName()}),
gen(constants.ProfilesIntegrationAuthz, constants.ProfilesIntegrationV0, sidecar.IntegrationAuthorizationV0{}),
gen(constants.ProfilesIntegrationAuthn, constants.ProfilesIntegrationV1, sidecar.IntegrationAuthenticationV1{Spec: spec, DeploymentName: apiObject.GetName()}),
gen(constants.ProfilesIntegrationSched, constants.ProfilesIntegrationV1, sidecar.IntegrationSchedulerV1{}),
); err != nil {
return err
} else if changed {
Expand Down
18 changes: 8 additions & 10 deletions pkg/handlers/scheduler/batchjob/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ func (h *handler) HandleObject(ctx context.Context, item operation.Item, extensi
return false, err
}

// Try to fetch status
if profileNames := util.FormatList(calculatedProfiles, func(a util.KV[string, schedulerApi.ProfileAcceptedTemplate]) string {
return a.K
}); !equality.Semantic.DeepEqual(status.Profiles, profileNames) {
status.Profiles = profileNames
return true, operator.Reconcile("Status Changed")
}

var batchJobTemplate batch.Job
batchJobTemplate.ObjectMeta = meta.ObjectMeta{
Name: extension.ObjectMeta.Name,
Expand Down Expand Up @@ -168,16 +176,6 @@ func (h *handler) HandleObject(ctx context.Context, item operation.Item, extensi
return false, err
}

profileNames := util.FormatList(calculatedProfiles, func(a util.KV[string, schedulerApi.ProfileAcceptedTemplate]) string {
return a.K
})

// Try to fetch status
if !equality.Semantic.DeepEqual(status.Profiles, profileNames) {
status.Profiles = profileNames
return true, operator.Reconcile("Status Changed")
}

// Try to fetch status
if !equality.Semantic.DeepEqual(status.JobStatus, obj.Status) {
obj.Status.DeepCopyInto(&status.JobStatus)
Expand Down
Loading
0