Skip to content

Commit 01f5875

Browse files
authored
[Feature] [Scheduler] SchedV1 Integration (#1732)
1 parent 9f0e5c5 commit 01f5875

File tree

13 files changed

+442
-44
lines changed

13 files changed

+442
-44
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- (Feature) (Scheduler) Create Integration Profile
3737
- (Feature) (Scheduler) Additional types
3838
- (Feature) Alternative Upgrade Order Feature
39+
- (Feature) (Scheduler) SchedV1 Integration
3940

4041
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
4142
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries

pkg/debug_package/generators/kubernetes/arango_scheduler.go

+20
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,25 @@ func scheduler(logger zerolog.Logger, files chan<- shared.File) error {
4343
return err
4444
}
4545

46+
if err := schedulerPods(logger, files, k); err != nil {
47+
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
48+
return err
49+
}
50+
51+
if err := schedulerDeployments(logger, files, k); err != nil {
52+
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
53+
return err
54+
}
55+
56+
if err := schedulerBatchJobs(logger, files, k); err != nil {
57+
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
58+
return err
59+
}
60+
61+
if err := schedulerCronJobs(logger, files, k); err != nil {
62+
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
63+
return err
64+
}
65+
4666
return nil
4767
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package kubernetes
22+
23+
import (
24+
"context"
25+
"fmt"
26+
27+
"github.com/rs/zerolog"
28+
29+
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
30+
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
31+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
32+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
33+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
35+
)
36+
37+
func schedulerBatchJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
batchjobs, err := listSchedulerBatchJobs(client)
39+
if err != nil {
40+
if kerrors.IsForbiddenOrNotFound(err) {
41+
return nil
42+
}
43+
44+
return err
45+
}
46+
47+
if err := errors.ExecuteWithErrorArrayP2(schedulerBatchJob, client, files, batchjobs...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango scheduler batchjobs")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func schedulerBatchJob(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerBatchJob) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerbatchjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listSchedulerBatchJobs(client kclient.Client) ([]*schedulerApi.ArangoSchedulerBatchJob, error) {
64+
return ListObjects[*schedulerApi.ArangoSchedulerBatchJobList, *schedulerApi.ArangoSchedulerBatchJob](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerBatchJobs(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerBatchJobList) []*schedulerApi.ArangoSchedulerBatchJob {
65+
q := make([]*schedulerApi.ArangoSchedulerBatchJob, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package kubernetes
22+
23+
import (
24+
"context"
25+
"fmt"
26+
27+
"github.com/rs/zerolog"
28+
29+
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
30+
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
31+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
32+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
33+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
35+
)
36+
37+
func schedulerCronJobs(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
cronjobs, err := listSchedulerCronJobs(client)
39+
if err != nil {
40+
if kerrors.IsForbiddenOrNotFound(err) {
41+
return nil
42+
}
43+
44+
return err
45+
}
46+
47+
if err := errors.ExecuteWithErrorArrayP2(schedulerCronJob, client, files, cronjobs...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango scheduler cronjobs")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func schedulerCronJob(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerCronJob) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulercronjobs/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listSchedulerCronJobs(client kclient.Client) ([]*schedulerApi.ArangoSchedulerCronJob, error) {
64+
return ListObjects[*schedulerApi.ArangoSchedulerCronJobList, *schedulerApi.ArangoSchedulerCronJob](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerCronJobs(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerCronJobList) []*schedulerApi.ArangoSchedulerCronJob {
65+
q := make([]*schedulerApi.ArangoSchedulerCronJob, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package kubernetes
22+
23+
import (
24+
"context"
25+
"fmt"
26+
27+
"github.com/rs/zerolog"
28+
29+
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
30+
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
31+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
32+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
33+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
35+
)
36+
37+
func schedulerDeployments(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
deployments, err := listSchedulerDeployments(client)
39+
if err != nil {
40+
if kerrors.IsForbiddenOrNotFound(err) {
41+
return nil
42+
}
43+
44+
return err
45+
}
46+
47+
if err := errors.ExecuteWithErrorArrayP2(schedulerDeployment, client, files, deployments...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango scheduler deployments")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func schedulerDeployment(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerDeployment) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerdeployments/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listSchedulerDeployments(client kclient.Client) ([]*schedulerApi.ArangoSchedulerDeployment, error) {
64+
return ListObjects[*schedulerApi.ArangoSchedulerDeploymentList, *schedulerApi.ArangoSchedulerDeployment](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerDeployments(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerDeploymentList) []*schedulerApi.ArangoSchedulerDeployment {
65+
q := make([]*schedulerApi.ArangoSchedulerDeployment, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package kubernetes
22+
23+
import (
24+
"context"
25+
"fmt"
26+
27+
"github.com/rs/zerolog"
28+
29+
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
30+
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
31+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
32+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
33+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
35+
)
36+
37+
func schedulerPods(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
pods, err := listSchedulerPods(client)
39+
if err != nil {
40+
if kerrors.IsForbiddenOrNotFound(err) {
41+
return nil
42+
}
43+
44+
return err
45+
}
46+
47+
if err := errors.ExecuteWithErrorArrayP2(schedulerPod, client, files, pods...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango scheduler pods")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func schedulerPod(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoSchedulerPod) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/arangoschedulerpods/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listSchedulerPods(client kclient.Client) ([]*schedulerApi.ArangoSchedulerPod, error) {
64+
return ListObjects[*schedulerApi.ArangoSchedulerPodList, *schedulerApi.ArangoSchedulerPod](context.Background(), client.Arango().SchedulerV1beta1().ArangoSchedulerPods(cli.GetInput().Namespace), func(result *schedulerApi.ArangoSchedulerPodList) []*schedulerApi.ArangoSchedulerPod {
65+
q := make([]*schedulerApi.ArangoSchedulerPod, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}

pkg/deployment/resources/arango_profiles.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
8181
return "", nil, err
8282
}
8383

84+
key, v := constants.NewProfileIntegration(name, version)
85+
8486
return fullName, &schedulerApi.ArangoProfile{
8587
ObjectMeta: meta.ObjectMeta{
8688
Name: fullName,
@@ -91,8 +93,8 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
9193
},
9294
Spec: schedulerApi.ProfileSpec{
9395
Selectors: matchArangoProfilesLabels(map[string]string{
94-
constants.ProfilesDeployment: deploymentName,
95-
fmt.Sprintf("%s/%s", constants.ProfilesIntegrationPrefix, name): version,
96+
constants.ProfilesDeployment: deploymentName,
97+
key: v,
9698
}),
9799
Template: integration,
98100
},
@@ -128,8 +130,9 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
128130
},
129131
}, nil
130132
},
131-
gen("authz", "v0", sidecar.IntegrationAuthorizationV0{}),
132-
gen("authn", "v1", sidecar.IntegrationAuthenticationV1{Spec: spec, DeploymentName: apiObject.GetName()}),
133+
gen(constants.ProfilesIntegrationAuthz, constants.ProfilesIntegrationV0, sidecar.IntegrationAuthorizationV0{}),
134+
gen(constants.ProfilesIntegrationAuthn, constants.ProfilesIntegrationV1, sidecar.IntegrationAuthenticationV1{Spec: spec, DeploymentName: apiObject.GetName()}),
135+
gen(constants.ProfilesIntegrationSched, constants.ProfilesIntegrationV1, sidecar.IntegrationSchedulerV1{}),
133136
); err != nil {
134137
return err
135138
} else if changed {

pkg/handlers/scheduler/batchjob/handler.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ func (h *handler) HandleObject(ctx context.Context, item operation.Item, extensi
109109
return false, err
110110
}
111111

112+
// Try to fetch status
113+
if profileNames := util.FormatList(calculatedProfiles, func(a util.KV[string, schedulerApi.ProfileAcceptedTemplate]) string {
114+
return a.K
115+
}); !equality.Semantic.DeepEqual(status.Profiles, profileNames) {
116+
status.Profiles = profileNames
117+
return true, operator.Reconcile("Status Changed")
118+
}
119+
112120
var batchJobTemplate batch.Job
113121
batchJobTemplate.ObjectMeta = meta.ObjectMeta{
114122
Name: extension.ObjectMeta.Name,
@@ -168,16 +176,6 @@ func (h *handler) HandleObject(ctx context.Context, item operation.Item, extensi
168176
return false, err
169177
}
170178

171-
profileNames := util.FormatList(calculatedProfiles, func(a util.KV[string, schedulerApi.ProfileAcceptedTemplate]) string {
172-
return a.K
173-
})
174-
175-
// Try to fetch status
176-
if !equality.Semantic.DeepEqual(status.Profiles, profileNames) {
177-
status.Profiles = profileNames
178-
return true, operator.Reconcile("Status Changed")
179-
}
180-
181179
// Try to fetch status
182180
if !equality.Semantic.DeepEqual(status.JobStatus, obj.Status) {
183181
obj.Status.DeepCopyInto(&status.JobStatus)

0 commit comments

Comments
 (0)