Skip to content

Commit bc8489b

Browse files
committed
Use structured configuration
1 parent 97262cb commit bc8489b

File tree

10 files changed

+87
-68
lines changed

10 files changed

+87
-68
lines changed

.github/workflows/e2e_tests.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ jobs:
7373
echo Deploying CodeFlare operator
7474
IMG="${REGISTRY_ADDRESS}"/codeflare-operator
7575
make image-push -e IMG="${IMG}"
76-
# FIXME
77-
kubectl create ns openshift-operators
78-
kubectl apply -n openshift-operators -f config/default/instascale-configmap.yaml
7976
make deploy -e IMG="${IMG}"
8077
kubectl wait --timeout=120s --for=condition=Available=true deployment -n openshift-operators codeflare-operator-manager
8178

.github/workflows/olm_tests.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ jobs:
117117
118118
- name: Deploy CodeFlare stack
119119
run: |
120-
# FIXME
121-
kubectl apply -n openshift-operators -f config/default/instascale-configmap.yaml
122-
123120
make setup-e2e
124121
125122
- name: Build operator and catalog image

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ COPY go.mod go.mod
77
COPY go.sum go.sum
88
RUN go mod download
99

10-
# Copy the go source
10+
# Copy the Go sources
1111
COPY main.go main.go
12+
COPY pkg/ pkg/
1213

1314
# Build
1415
USER root

config/default/instascale-configmap.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/default/kustomization.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ bases:
2828
resources:
2929
# Add metrics service
3030
- metrics_service.yaml
31-
# TODO: refactor configuration
32-
- instascale-configmap.yaml
3331

3432
# Mount the controller config file for loading manager configurations
3533
# through a ComponentConfig type

config/manager/manager.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ spec:
3737
args:
3838
- "--health-probe-bind-address=:8081"
3939
- "--metrics-bind-address=0.0.0.0:8082"
40-
- "--leader-elect"
41-
- "--configs-namespace=openshift-operators"
4240
image: controller:latest
4341
imagePullPolicy: Always
4442
name: manager

go.mod

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ require (
77
github.com/openshift-eng/openshift-goimports v0.0.0-20230304234052-c70783e636f2
88
github.com/openshift/api v0.0.0-20230213134911-7ba313770556
99
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
10-
github.com/project-codeflare/instascale v0.0.0-00010101000000-000000000000
11-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1-0.20230904071404-ce734452edc6
10+
github.com/project-codeflare/instascale v0.0.9-0.20230913044449-3db3f4b4e9b1
11+
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.2-0.20230913035103-6e7bbdc8fb1f
1212
github.com/ray-project/kuberay/ray-operator v0.0.0-20230908233208-a8f730e5a2b6
1313
go.uber.org/zap v1.24.0
1414
k8s.io/api v0.26.3
1515
k8s.io/apimachinery v0.26.3
1616
k8s.io/client-go v0.26.3
17+
k8s.io/component-base v0.26.2
18+
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
1719
sigs.k8s.io/controller-runtime v0.14.6
1820
)
1921

20-
replace (
21-
github.com/project-codeflare/instascale => github.com/Bobbins228/instascale v0.0.0-20230724130835-2a8ebf58690f
22-
sigs.k8s.io/custom-metrics-apiserver => sigs.k8s.io/custom-metrics-apiserver v1.25.1-0.20230306170449-63d8c93851f3
23-
)
22+
replace sigs.k8s.io/custom-metrics-apiserver => sigs.k8s.io/custom-metrics-apiserver v1.25.1-0.20230306170449-63d8c93851f3
2423

2524
require (
2625
github.com/NYTimes/gziphandler v1.1.1 // indirect
@@ -125,13 +124,11 @@ require (
125124
gopkg.in/yaml.v3 v3.0.1 // indirect
126125
k8s.io/apiextensions-apiserver v0.26.1 // indirect
127126
k8s.io/apiserver v0.26.2 // indirect
128-
k8s.io/component-base v0.26.2 // indirect
129127
k8s.io/klog v1.0.0 // indirect
130128
k8s.io/klog/v2 v2.90.1 // indirect
131129
k8s.io/kms v0.26.2 // indirect
132130
k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d // indirect
133131
k8s.io/metrics v0.26.2 // indirect
134-
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
135132
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.35 // indirect
136133
sigs.k8s.io/custom-metrics-apiserver v0.0.0 // indirect
137134
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
3333
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
3434
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3535
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
36-
github.com/Bobbins228/instascale v0.0.0-20230724130835-2a8ebf58690f h1:aEtM6OZ2dCY97VnVsVYZl2GJOe+6WegPGLgLXQt5BGk=
37-
github.com/Bobbins228/instascale v0.0.0-20230724130835-2a8ebf58690f/go.mod h1:kwBkC+o4W+a1dpftXbVQjvGCVyu2206HlZtcp1+ZjyY=
3836
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
3937
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4038
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
@@ -460,8 +458,10 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
460458
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
461459
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
462460
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
463-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1-0.20230904071404-ce734452edc6 h1:YT6C0Z84TgftYcoNUd/dwvXxGJvXy67EeWAMQjpKvdU=
464-
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.1-0.20230904071404-ce734452edc6/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
461+
github.com/project-codeflare/instascale v0.0.9-0.20230913044449-3db3f4b4e9b1 h1:SNc05sEO/KBuRwep+u7J/ZrT06IhncjTHBvopc4LDlU=
462+
github.com/project-codeflare/instascale v0.0.9-0.20230913044449-3db3f4b4e9b1/go.mod h1:n2fIzs06LmGZFB3vRfQcXOkPebN3Hwd5Y+SD5v0hnrs=
463+
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.2-0.20230913035103-6e7bbdc8fb1f h1:xrhSm18A/Gvmm9cia05eAGkj0i9fTMqeTExz8rQTHJU=
464+
github.com/project-codeflare/multi-cluster-app-dispatcher v1.34.2-0.20230913035103-6e7bbdc8fb1f/go.mod h1:Yge6GRNpO9YIDfeL+XOcCE9xbmfCTD5C1h5dlW87mxQ=
465465
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
466466
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
467467
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

main.go

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ import (
2222
"time"
2323

2424
instascale "github.com/project-codeflare/instascale/controllers"
25-
mcadoptions "github.com/project-codeflare/multi-cluster-app-dispatcher/cmd/kar-controllers/app/options"
2625
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
26+
mcadconfig "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/config"
2727
mcad "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/queuejob"
2828
"go.uber.org/zap/zapcore"
2929

3030
"k8s.io/apimachinery/pkg/runtime"
3131
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3232
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3333
_ "k8s.io/client-go/plugin/pkg/client/auth"
34+
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
35+
"k8s.io/utils/pointer"
3436
ctrl "sigs.k8s.io/controller-runtime"
3537
"sigs.k8s.io/controller-runtime/pkg/healthz"
3638
"sigs.k8s.io/controller-runtime/pkg/log/zap"
39+
40+
"github.com/project-codeflare/codeflare-operator/pkg/config"
3741
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3842
// to ensure that exec-entrypoint and run can make use of them.
3943
// +kubebuilder:scaffold:imports
@@ -51,73 +55,60 @@ func init() {
5155

5256
func main() {
5357
var metricsAddr string
54-
var enableLeaderElection bool
5558
var probeAddr string
56-
var configsNamespace string
57-
var ocmSecretNamespace string
5859

59-
// Operator
6060
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6161
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
62-
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
63-
"Enable leader election for controller manager. "+
64-
"Enabling this will ensure there is only one active controller manager.")
65-
66-
// InstScale
67-
flag.StringVar(&configsNamespace, "configs-namespace", "kube-system", "The namespace containing the Instacale configmap")
68-
flag.StringVar(&ocmSecretNamespace, "ocm-secret-namespace", "default", "The namespace containing the OCM secret")
69-
70-
mcadOptions := mcadoptions.NewServerOption()
7162

7263
zapOptions := zap.Options{
7364
Development: true,
7465
TimeEncoder: zapcore.TimeEncoderOfLayout(time.RFC3339),
7566
}
76-
77-
flagSet := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
78-
flag.CommandLine.VisitAll(func(f *flag.Flag) {
79-
if f.Name != "kubeconfig" {
80-
flagSet.Var(f.Value, f.Name, f.Usage)
81-
}
82-
})
83-
84-
zapOptions.BindFlags(flagSet)
85-
mcadOptions.AddFlags(flagSet)
86-
_ = flagSet.Parse(os.Args[1:])
67+
zapOptions.BindFlags(flag.CommandLine)
8768

8869
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions)))
8970

9071
ctx := ctrl.SetupSignalHandler()
9172

73+
cfg := config.CodeFlareOperatorConfiguration{
74+
LeaderElection: &configv1alpha1.LeaderElectionConfiguration{},
75+
MCAD: &mcadconfig.MCADConfiguration{},
76+
InstaScale: &config.InstaScaleConfiguration{},
77+
}
78+
9279
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
93-
Scheme: scheme,
94-
MetricsBindAddress: metricsAddr,
95-
Port: 9443,
96-
HealthProbeBindAddress: probeAddr,
97-
LeaderElection: enableLeaderElection,
98-
LeaderElectionID: "5a3ca514.codeflare.dev",
80+
Scheme: scheme,
81+
MetricsBindAddress: metricsAddr,
82+
HealthProbeBindAddress: probeAddr,
83+
LeaderElection: pointer.BoolDeref(cfg.LeaderElection.LeaderElect, false),
84+
LeaderElectionID: cfg.LeaderElection.ResourceName,
85+
LeaderElectionNamespace: cfg.LeaderElection.ResourceNamespace,
86+
LeaderElectionResourceLock: cfg.LeaderElection.ResourceLock,
87+
LeaseDuration: &cfg.LeaderElection.LeaseDuration.Duration,
88+
RetryPeriod: &cfg.LeaderElection.RetryPeriod.Duration,
89+
RenewDeadline: &cfg.LeaderElection.RenewDeadline.Duration,
9990
})
10091
if err != nil {
10192
setupLog.Error(err, "unable to start manager")
10293
os.Exit(1)
10394
}
10495

105-
mcadQueueController := mcad.NewJobController(mgr.GetConfig(), mcadOptions)
96+
mcadQueueController := mcad.NewJobController(mgr.GetConfig(), cfg.MCAD, &mcadconfig.MCADConfigurationExtended{})
10697
if mcadQueueController == nil {
10798
// FIXME
10899
os.Exit(1)
109100
}
110101
mcadQueueController.Run(ctx.Done())
111102

112-
instascaleController := &instascale.AppWrapperReconciler{
113-
Client: mgr.GetClient(),
114-
Scheme: mgr.GetScheme(),
115-
ConfigsNamespace: configsNamespace,
116-
OcmSecretNamespace: ocmSecretNamespace,
103+
if pointer.BoolDeref(cfg.InstaScale.Enabled, false) {
104+
instaScaleController := &instascale.AppWrapperReconciler{
105+
Client: mgr.GetClient(),
106+
Scheme: mgr.GetScheme(),
107+
Config: cfg.InstaScale.InstaScaleConfiguration,
108+
}
109+
exitOnError(instaScaleController.SetupWithManager(mgr), "Error setting up InstaScale controller")
117110
}
118111

119-
exitOnError(instascaleController.SetupWithManager(mgr), "Error setting up InstaScale controller")
120-
121112
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
122113
setupLog.Error(err, "unable to set up health check")
123114
os.Exit(1)

pkg/config/config.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import (
20+
instascale "github.com/project-codeflare/instascale/pkg/config"
21+
mcad "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/config"
22+
23+
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
24+
)
25+
26+
type CodeFlareOperatorConfiguration struct {
27+
// LeaderElection is the LeaderElection config to be used when configuring
28+
// the manager.Manager leader election
29+
LeaderElection *configv1alpha1.LeaderElectionConfiguration `json:"leaderElection,omitempty"`
30+
31+
// The MCAD controller configuration
32+
MCAD *mcad.MCADConfiguration `json:"mcad,omitempty"`
33+
34+
// The InstaScale controller configuration
35+
InstaScale *InstaScaleConfiguration `json:"instascale,omitempty"`
36+
}
37+
38+
type InstaScaleConfiguration struct {
39+
// enabled controls whether the InstaScale controller is started.
40+
// It may default to true on platforms that InstaScale supports.
41+
// Otherwise, it defaults to false.
42+
Enabled *bool `json:"enabled,omitempty"`
43+
44+
// The InstaScale controller configuration
45+
instascale.InstaScaleConfiguration `json:",inline,omitempty"`
46+
}

0 commit comments

Comments
 (0)