forked from fluid-cloudnative/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fluid app controller (fluid-cloudnative#1481)
* add fluid app controller Signed-off-by: zwwhdls <zww@hdls.me> * fix ci-lint Signed-off-by: zwwhdls <zww@hdls.me> * add watch func in fluid app controller Signed-off-by: zwwhdls <zww@hdls.me> * fix chart lint Signed-off-by: zwwhdls <zww@hdls.me> * reduce rbac Signed-off-by: zwwhdls <zww@hdls.me> * use util instead Signed-off-by: zwwhdls <zww@hdls.me> * update rbac Signed-off-by: zwwhdls <zww@hdls.me> * update rbac Signed-off-by: zwwhdls <zww@hdls.me>
- Loading branch information
Showing
18 changed files
with
1,328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
charts/fluid/fluid/templates/controller/fluidapp_controller.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{{ if .Values.fluidapp.enabled -}} | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: fluidapp-controller | ||
namespace: fluid-system | ||
labels: | ||
control-plane: fluidapp-controller | ||
spec: | ||
selector: | ||
matchLabels: | ||
control-plane: fluidapp-controller | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
control-plane: fluidapp-controller | ||
spec: | ||
serviceAccountName: fluidapp-controller | ||
affinity: | ||
nodeAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: type | ||
operator: NotIn | ||
values: | ||
- virtual-kubelet | ||
tolerations: | ||
- operator: Exists | ||
#hostNetwork: true | ||
containers: | ||
- image: "{{ .Values.fluidapp.controller.image }}" | ||
name: manager | ||
command: ["fluidapp-controller", "start"] | ||
args: | ||
- --development=false | ||
- --pprof-addr=:6060 | ||
env: | ||
{{- if .Values.workdir }} | ||
- name: FLUID_WORKDIR | ||
value: {{ .Values.workdir | quote }} | ||
{{- end }} | ||
ports: | ||
- containerPort: 8080 | ||
name: metrics | ||
protocol: TCP | ||
resources: | ||
limits: | ||
cpu: 100m | ||
memory: 1536Mi | ||
requests: | ||
cpu: 100m | ||
memory: 200Mi | ||
terminationGracePeriodSeconds: 10 | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: fluidapp-controller | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- events | ||
verbs: | ||
- get | ||
- watch | ||
- create | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- pods | ||
- pods/exec | ||
verbs: | ||
- get | ||
- list | ||
- patch | ||
- update | ||
- watch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: fluidapp-clusterrolebinding | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: fluidapp-controller | ||
subjects: | ||
- kind: ServiceAccount | ||
name: fluidapp-controller | ||
namespace: fluid-system | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: fluidapp-controller | ||
namespace: fluid-system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright 2022 The Fluid Authors. | ||
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. | ||
*/ | ||
|
||
package app | ||
|
||
import ( | ||
"github.com/fluid-cloudnative/fluid" | ||
"github.com/fluid-cloudnative/fluid/pkg/controllers/v1alpha1/fluidapp" | ||
"github.com/fluid-cloudnative/fluid/pkg/utils" | ||
"github.com/spf13/cobra" | ||
zapOpt "go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
"os" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
) | ||
|
||
var ( | ||
scheme = runtime.NewScheme() | ||
setupLog = ctrl.Log.WithName("setup") | ||
|
||
metricsAddr string | ||
enableLeaderElection bool | ||
development bool | ||
maxConcurrentReconciles int | ||
pprofAddr string | ||
) | ||
|
||
var fluidAppCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "start fluidapp-controller in Kubernetes", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
handle() | ||
}, | ||
} | ||
|
||
func init() { | ||
_ = clientgoscheme.AddToScheme(scheme) | ||
_ = corev1.AddToScheme(scheme) | ||
fluidAppCmd.Flags().StringVarP(&metricsAddr, "metrics-addr", "", ":8080", "The address the metric endpoint binds to.") | ||
fluidAppCmd.Flags().BoolVarP(&enableLeaderElection, "enable-leader-election", "", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") | ||
fluidAppCmd.Flags().BoolVarP(&development, "development", "", true, "Enable development mode for fluid controller.") | ||
fluidAppCmd.Flags().StringVarP(&pprofAddr, "pprof-addr", "", "", "The address for pprof to use while exporting profiling results") | ||
fluidAppCmd.Flags().IntVar(&maxConcurrentReconciles, "runtime-workers", 3, "Set max concurrent workers for Fluid App controller") | ||
} | ||
|
||
func handle() { | ||
fluid.LogVersion() | ||
|
||
ctrl.SetLogger(zap.New(func(o *zap.Options) { | ||
o.Development = development | ||
}, func(o *zap.Options) { | ||
o.ZapOpts = append(o.ZapOpts, zapOpt.AddCaller()) | ||
}, func(o *zap.Options) { | ||
if !development { | ||
encCfg := zapOpt.NewProductionEncoderConfig() | ||
encCfg.EncodeLevel = zapcore.CapitalLevelEncoder | ||
encCfg.EncodeTime = zapcore.ISO8601TimeEncoder | ||
o.Encoder = zapcore.NewConsoleEncoder(encCfg) | ||
} | ||
})) | ||
|
||
utils.NewPprofServer(setupLog, pprofAddr) | ||
|
||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
Scheme: scheme, | ||
MetricsBindAddress: metricsAddr, | ||
LeaderElection: enableLeaderElection, | ||
LeaderElectionID: "4fa6ffa6.data.fluid.io", | ||
Port: 9443, | ||
}) | ||
if err != nil { | ||
setupLog.Error(err, "unable to start fluid app manager") | ||
os.Exit(1) | ||
} | ||
|
||
controllerOptions := controller.Options{ | ||
MaxConcurrentReconciles: maxConcurrentReconciles, | ||
} | ||
if err = (fluidapp.NewFluidAppReconciler( | ||
mgr.GetClient(), | ||
ctrl.Log.WithName("appctrl"), | ||
mgr.GetEventRecorderFor("FluidApp"), | ||
)).SetupWithManager(mgr, controllerOptions); err != nil { | ||
setupLog.Error(err, "unable to create controller", "controller", "FluidApp") | ||
os.Exit(1) | ||
} | ||
|
||
setupLog.Info("starting fluidapp-controller") | ||
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { | ||
setupLog.Error(err, "problem running fluidapp-controller") | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2022 The Fluid Authors. | ||
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. | ||
*/ | ||
|
||
package app | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
func NewFluidAppCommand() *cobra.Command { | ||
command := &cobra.Command{ | ||
Use: "fluidapp-controller", | ||
Short: "controller for fluidapp", | ||
} | ||
|
||
command.AddCommand(versionCmd, fluidAppCmd) | ||
|
||
return command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright 2022 The Fluid Authors. | ||
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. | ||
*/ | ||
|
||
package app | ||
|
||
import ( | ||
"github.com/fluid-cloudnative/fluid" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
short bool | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "print version information", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fluid.PrintVersion(short) | ||
}, | ||
} | ||
|
||
func init() { | ||
versionCmd.Flags().BoolVar(&short, "short", false, "print just the short version info") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2022 The Fluid Authors. | ||
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. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fluid-cloudnative/fluid/cmd/fluidapp/app" | ||
"os" | ||
) | ||
|
||
func main() { | ||
command := app.NewFluidAppCommand() | ||
if err := command.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "%s", err.Error()) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.