Compare commits

..

3 Commits

Author SHA1 Message Date
Hongchao Deng
92a887c1dc Merge pull request #1831 from wonderflow/fixdev
add application  controller to caps which can be disabled and remove appdeployment
2021-06-22 02:34:12 -07:00
天元
b3eaea0912 add application controller to caps which can be disabled and remove appdeployment 2021-06-22 16:51:16 +08:00
yangsoon
e320a4b027 add more options for vela-controller (#1769)
* add more option for controller

1. add ConcurrentReconciles for setting the concurrent reconcile number of the controller
2. add DependCheckWait for setting the time to wait for ApplicationConfiguration's dependent-resource ready

* fix test

* add controller reference
2021-06-08 10:30:00 +08:00
16 changed files with 95 additions and 39 deletions

View File

@@ -125,7 +125,7 @@ docker-push:
docker push ${IMG}
e2e-setup:
bin/vela install --set installCertManager=true --image-pull-policy IfNotPresent --image-repo vela-core-test --image-tag $(GIT_COMMIT)
bin/vela install --set installCertManager=true --image-pull-policy IfNotPresent --image-repo vela-core-test --image-tag $(GIT_COMMIT) --depend-check-wait 10s
ginkgo version
ginkgo -v -r e2e/setup
kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=vela-core,app.kubernetes.io/instance=kubevela -n vela-system --timeout=600s

View File

@@ -117,6 +117,8 @@ spec:
{{ if ne .Values.disableCaps "" }}
- "--disable-caps={{ .Values.disableCaps }}"
{{ end }}
- "--concurrent-reconciles={{ .Values.concurrentReconciles }}"
- "--depend-check-wait={{ .Values.dependCheckWait }}"
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ quote .Values.image.pullPolicy }}
resources:

View File

@@ -86,3 +86,9 @@ certificate:
caBundle: replace-me
systemDefinitionNamespace: vela-system
# concurrentReconciles is the concurrent reconcile number of the controller
concurrentReconciles: 4
# dependCheckWait is the time to wait for ApplicationConfiguration's dependent-resource ready
dependCheckWait: 30s

View File

@@ -100,11 +100,13 @@ func main() {
"custom-revision-hook-url is a webhook url which will let KubeVela core to call with applicationConfiguration and component info and return a customized component revision")
flag.StringVar(&disableCaps, "disable-caps", "", "To be disabled builtin capability list.")
flag.StringVar(&storageDriver, "storage-driver", driver.LocalDriverName, "Application file save to the storage driver")
flag.DurationVar(&syncPeriod, "informer-re-sync-interval", 5*time.Minute,
"controller shared informer lister full re-sync period")
flag.DurationVar(&syncPeriod, "informer-re-sync-interval", 2*time.Hour, "controller shared informer lister full re-sync period. The default value is 2 hours")
flag.StringVar(&oam.SystemDefinitonNamespace, "system-definition-namespace", "vela-system", "define the namespace of the system-level definition")
flag.DurationVar(&controllerArgs.LongWait, "long-wait", 1*time.Minute, "long-wait is controller next reconcile interval time like 30s, 2m etc. The default value is 1m,"+
" you can set it to 0 for no reconcile routine after success")
flag.IntVar(&controllerArgs.ConcurrentReconciles, "concurrent-reconciles", 4, "concurrent-reconciles is the concurrent reconcile number of the controller. The default value is 4")
flag.DurationVar(&controllerArgs.DependCheckWait, "depend-check-wait", 30*time.Second, "depend-check-wait is the time to wait for ApplicationConfiguration's dependent-resource ready."+
"The default value is 30s, which means if dependent resources were not prepared, the ApplicationConfiguration would be reconciled after 30s.")
flag.Parse()
// setup logging

View File

@@ -0,0 +1,24 @@
# KubeVela Controller Parameters Reference
| parameter | type | default | describe |
| :-------------------------: | :----: | :-------------------------------: | :----------------------------------------------------------: |
| use-webhook | bool | false | Enable Admission Webhook |
| use-trait-injector | bool | false | Enable TraitInjector |
| webhook-cert-dir | string | /k8s-webhook-server/serving-certs | Admission webhook cert/key dir. |
| metrics-addr | string | :8080 | The address the metric endpoint binds to. |
| enable-leader-election | bool | false | Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager. |
| leader-election-namespace | string | "" | Determines the namespace in which the leader election configmap will be created. |
| log-file-path | string | "" | The file to write logs to. |
| log-retain-date | int | 7 | The number of days of logs history to retain. |
| log-compress | bool | true | Enable compression on the rotated logs. |
| revision-limit | int | 50 | revision-limit is the maximum number of revisions that will be maintained. The default value is 50. |
| health-addr | string | :9440 | The address the health endpoint binds to. |
| apply-once-only | string | false | For the purpose of some production environment that workload or trait should not be affected if no spec change, available options: on, off, force. |
| custom-revision-hook-url | string | "" | custom-revision-hook-url is a webhook url which will let KubeVela core to call with applicationConfiguration and component info and return a customized component revision |
| disable-caps | string | "" | To be disabled builtin capability list. |
| storage-driver | string | Local | Application file save to the storage driver |
| informer-re-sync-interval | time | 2h | controller shared informer lister full re-sync period |
| system-definition-namespace | string | vela-system | define the namespace of the system-level definition |
| long-wait | time | 1m | long-wait is controller next reconcile interval time like 30s, 2m etc. The default value is 1m, you can set it to 0 for no reconcile routine after success |
| concurrent-reconciles | int | 4 | concurrent-reconciles is the concurrent reconcile number of the controller. |
| depend-check-wait | time | 30s | depend-check-wait is the time to wait for ApplicationConfiguration's dependent-resource ready. |

View File

@@ -48,6 +48,7 @@ type chartArgs struct {
imageRepo string
imageTag string
imagePullPolicy string
dependCheckWait string
more []string
}
@@ -131,6 +132,7 @@ func NewInstallCommand(c types.Args, chartContent string, ioStreams cmdutil.IOSt
flag.StringVarP(&i.chartArgs.imagePullPolicy, "image-pull-policy", "", "", "vela core image pull policy, this will align to chart value image.pullPolicy")
flag.StringVarP(&i.chartArgs.imageRepo, "image-repo", "", "", "vela core image repo, this will align to chart value image.repo")
flag.StringVarP(&i.chartArgs.imageTag, "image-tag", "", "", "vela core image repo, this will align to chart value image.tag")
flag.StringVarP(&i.chartArgs.dependCheckWait, "depend-check-wait", "", "", "depend-check-wait, this the time to wait for ApplicationConfiguration's dependent-resource ready")
flag.StringVarP(&i.waitReady, "wait", "w", "0s", "wait until vela-core is ready to serve, default will not wait")
flag.StringSliceVarP(&i.chartArgs.more, "set", "s", []string{}, "arguments for installing vela-core chart")
@@ -228,6 +230,9 @@ func (i *initCmd) resolveValues() (map[string]interface{}, error) {
if i.chartArgs.imagePullPolicy != "" {
valuesConfig = append(valuesConfig, fmt.Sprintf("image.pullPolicy=%s", i.chartArgs.imagePullPolicy))
}
if i.chartArgs.dependCheckWait != "" {
valuesConfig = append(valuesConfig, fmt.Sprintf("dependCheckWait=%s", i.chartArgs.dependCheckWait))
}
valuesConfig = append(valuesConfig, i.chartArgs.more...)
for _, val := range valuesConfig {

View File

@@ -1,29 +1,13 @@
package common
import (
"reflect"
v1 "k8s.io/api/core/v1"
)
const (
// AutoscaleControllerName is the controller name of Trait autoscale
AutoscaleControllerName = "autoscale"
// MetricsControllerName is the controller name of Trait metrics
MetricsControllerName = "metrics"
// PodspecWorkloadControllerName is the controller name of Workload podsepcworkload
PodspecWorkloadControllerName = "podspecworkload"
// RouteControllerName is the controller name of Trait route
RouteControllerName = "route"
// ApplicationControllerName is the Application controller
ApplicationControllerName = "application"
// DisableAllCaps disable all capabilities
DisableAllCaps = "all"
// DisableNoneCaps disable none of capabilities
DisableNoneCaps = ""
)
// ServiceKind is string "Service"
var ServiceKind = reflect.TypeOf(v1.Service{}).Name()
// ServiceAPIVersion is string "v1"
var ServiceAPIVersion = v1.SchemeGroupVersion.String()

View File

@@ -52,4 +52,10 @@ type Args struct {
// LongWait is controller next reconcile interval time
LongWait time.Duration
// ConcurrentReconciles is the concurrent reconcile number of the controller
ConcurrentReconciles int
// DependCheckWait is the time to wait for ApplicationConfiguration's dependent-resource ready
DependCheckWait time.Duration
}

View File

@@ -22,7 +22,6 @@ import (
"time"
"github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/go-logr/logr"
"github.com/pkg/errors"
kerrors "k8s.io/apimachinery/pkg/api/errors"
@@ -34,7 +33,6 @@ import (
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/pkg/appfile"
core "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
oamutil "github.com/oam-dev/kubevela/pkg/oam/util"
@@ -178,7 +176,7 @@ func (r *Reconciler) UpdateStatus(ctx context.Context, app *v1alpha2.Application
}
// Setup adds a controller that reconciles ApplicationDeployment.
func Setup(mgr ctrl.Manager, _ core.Args, _ logging.Logger) error {
func Setup(mgr ctrl.Manager) error {
dm, err := discoverymapper.New(mgr.GetConfig())
if err != nil {
return fmt.Errorf("create discovery dm fail %w", err)

View File

@@ -31,6 +31,7 @@ import (
"k8s.io/client-go/util/retry"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
@@ -51,7 +52,6 @@ import (
const (
reconcileTimeout = 1 * time.Minute
dependCheckWait = 10 * time.Second
shortWait = 30 * time.Second
)
@@ -92,7 +92,12 @@ func Setup(mgr ctrl.Manager, args core.Args, l logging.Logger) error {
}
name := "oam/" + strings.ToLower(v1alpha2.ApplicationConfigurationGroupKind)
return ctrl.NewControllerManagedBy(mgr).
builder := ctrl.NewControllerManagedBy(mgr)
builder.WithOptions(controller.Options{
MaxConcurrentReconciles: args.ConcurrentReconciles,
})
return builder.
Named(name).
For(&v1alpha2.ApplicationConfiguration{}).
Watches(&source.Kind{Type: &v1alpha2.Component{}}, &ComponentHandler{
@@ -105,7 +110,8 @@ func Setup(mgr ctrl.Manager, args core.Args, l logging.Logger) error {
l.WithValues("controller", name),
WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
WithApplyOnceOnlyMode(args.ApplyMode),
WithLongWaitTime(args.LongWait)))
WithLongWaitTime(args.LongWait),
WithDependCheckWait(args.DependCheckWait)))
}
// An OAMApplicationReconciler reconciles OAM ApplicationConfigurations by rendering and
@@ -122,6 +128,7 @@ type OAMApplicationReconciler struct {
postHooks map[string]ControllerHooks
applyOnceOnlyMode core.ApplyOnceOnlyMode
longWait time.Duration
dependCheckWait time.Duration
}
// A ReconcilerOption configures a Reconciler.
@@ -186,6 +193,13 @@ func WithLongWaitTime(longWait time.Duration) ReconcilerOption {
}
}
// WithDependCheckWait set depend check wait
func WithDependCheckWait(dependCheckWait time.Duration) ReconcilerOption {
return func(r *OAMApplicationReconciler) {
r.dependCheckWait = dependCheckWait
}
}
// NewReconciler returns an OAMApplicationReconciler that reconciles ApplicationConfigurations
// by rendering and instantiating their Components and Traits.
func NewReconciler(m ctrl.Manager, dm discoverymapper.DiscoveryMapper, log logging.Logger, o ...ReconcilerOption) *OAMApplicationReconciler {
@@ -349,7 +363,7 @@ func (r *OAMApplicationReconciler) Reconcile(req reconcile.Request) (result reco
ac.Status.Dependency = v1alpha2.DependencyStatus{}
waitTime := r.longWait
if len(depStatus.Unsatisfied) != 0 {
waitTime = dependCheckWait
waitTime = r.dependCheckWait
ac.Status.Dependency = *depStatus
}

View File

@@ -183,6 +183,7 @@ func TestReconciler(t *testing.T) {
WithRenderer(ComponentRenderFn(func(_ context.Context, _ *v1alpha2.ApplicationConfiguration) ([]Workload, *v1alpha2.DependencyStatus, error) {
return nil, &v1alpha2.DependencyStatus{}, errBoom
})),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -212,6 +213,7 @@ func TestReconciler(t *testing.T) {
WithApplicator(WorkloadApplyFns{ApplyFn: func(_ context.Context, _ []v1alpha2.WorkloadStatus, _ []Workload, _ ...apply.ApplyOption) error {
return errBoom
}}),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -245,6 +247,7 @@ func TestReconciler(t *testing.T) {
WithGarbageCollector(GarbageCollectorFn(func(_ string, _ []v1alpha2.WorkloadStatus, _ []Workload) []unstructured.Unstructured {
return []unstructured.Unstructured{*workload}
})),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -308,10 +311,11 @@ func TestReconciler(t *testing.T) {
WithGarbageCollector(GarbageCollectorFn(func(_ string, _ []v1alpha2.WorkloadStatus, _ []Workload) []unstructured.Unstructured {
return []unstructured.Unstructured{*trait}
})),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
result: reconcile.Result{RequeueAfter: dependCheckWait},
result: reconcile.Result{RequeueAfter: 10 * time.Second},
},
},
"FailedPreHook": {
@@ -352,6 +356,7 @@ func TestReconciler(t *testing.T) {
WithPosthook("postHook", ControllerHooksFn(func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration, logger logging.Logger) (reconcile.Result, error) {
return reconcile.Result{RequeueAfter: shortWait}, nil
})),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -422,6 +427,7 @@ func TestReconciler(t *testing.T) {
WithPosthook("preHookFailed", ControllerHooksFn(func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration, logger logging.Logger) (reconcile.Result, error) {
return reconcile.Result{RequeueAfter: 15 * time.Second}, errBoom
})),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -472,6 +478,7 @@ func TestReconciler(t *testing.T) {
WithPosthook("preHookFailed", ControllerHooksFn(func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration, logger logging.Logger) (reconcile.Result, error) {
return reconcile.Result{RequeueAfter: 15 * time.Second}, errBoom
})),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -540,6 +547,7 @@ func TestReconciler(t *testing.T) {
return reconcile.Result{RequeueAfter: shortWait}, nil
})),
WithLongWaitTime(1 * time.Minute),
WithDependCheckWait(10 * time.Second),
},
},
want: want{
@@ -584,6 +592,9 @@ func TestReconciler(t *testing.T) {
MockStatusUpdate: test.NewMockStatusUpdateFn(nil),
},
},
o: []ReconcilerOption{
WithDependCheckWait(10 * time.Second),
},
},
want: want{
result: reconcile.Result{},
@@ -616,6 +627,9 @@ func TestReconciler(t *testing.T) {
MockStatusUpdate: test.NewMockStatusUpdateFn(nil),
},
},
o: []ReconcilerOption{
WithDependCheckWait(10 * time.Second),
},
},
want: want{
result: reconcile.Result{},
@@ -652,6 +666,7 @@ func TestReconciler(t *testing.T) {
WithApplicator(WorkloadApplyFns{FinalizeFn: func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration) error {
return errBoom
}}),
WithDependCheckWait(10 * time.Second),
},
},
want: want{

View File

@@ -6,7 +6,6 @@ import (
"time"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/logging"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ktypes "k8s.io/apimachinery/pkg/types"
@@ -18,7 +17,6 @@ import (
corev1alpha2 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/pkg/controller/common/rollout"
controller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
@@ -160,7 +158,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
}
// Setup adds a controller that reconciles ApplicationDeployment.
func Setup(mgr ctrl.Manager, _ controller.Args, _ logging.Logger) error {
func Setup(mgr ctrl.Manager) error {
dm, err := discoverymapper.New(mgr.GetConfig())
if err != nil {
return fmt.Errorf("create discovery dm fail %w", err)

View File

@@ -19,13 +19,10 @@ package v1alpha2
import (
ctrl "sigs.k8s.io/controller-runtime"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application"
"github.com/crossplane/crossplane-runtime/pkg/logging"
controller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/applicationconfiguration"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/applicationdeployment"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core/scopes/healthscope"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core/traits/manualscalertrait"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core/workloads/containerizedworkload"
@@ -36,7 +33,6 @@ func Setup(mgr ctrl.Manager, args controller.Args, l logging.Logger) error {
for _, setup := range []func(ctrl.Manager, controller.Args, logging.Logger) error{
applicationconfiguration.Setup,
containerizedworkload.Setup, manualscalertrait.Setup, healthscope.Setup,
application.Setup, applicationdeployment.Setup,
} {
if err := setup(mgr, args, l); err != nil {
return err

View File

@@ -20,6 +20,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"github.com/oam-dev/kubevela/pkg/controller/common"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application"
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/applicationdeployment"
"github.com/oam-dev/kubevela/pkg/controller/standard.oam.dev/v1alpha1/podspecworkload"
"github.com/oam-dev/kubevela/pkg/controller/utils"
)
@@ -31,6 +33,8 @@ func Setup(mgr ctrl.Manager, disableCaps string) error {
case common.DisableNoneCaps:
functions = []func(ctrl.Manager) error{
podspecworkload.Setup,
application.Setup,
applicationdeployment.Setup,
}
case common.DisableAllCaps:
default:
@@ -38,6 +42,9 @@ func Setup(mgr ctrl.Manager, disableCaps string) error {
if !disableCapsSet.Contains(common.PodspecWorkloadControllerName) {
functions = append(functions, podspecworkload.Setup)
}
if !disableCapsSet.Contains(common.ApplicationControllerName) {
functions = append(functions, application.Setup)
}
}
for _, setup := range functions {

View File

@@ -22,8 +22,7 @@ const LabelPodSpecable = "workload.oam.dev/podspecable"
// allBuiltinCapabilities includes all builtin controllers
// TODO(zzxwill) needs to automatically discovery all controllers
var allBuiltinCapabilities = mapset.NewSet(common.MetricsControllerName, common.PodspecWorkloadControllerName,
common.RouteControllerName, common.AutoscaleControllerName)
var allBuiltinCapabilities = mapset.NewSet(common.PodspecWorkloadControllerName, common.ApplicationControllerName)
// GetPodSpecPath get podSpec field and label
func GetPodSpecPath(workloadDef *v1alpha2.WorkloadDefinition) (string, bool) {

View File

@@ -18,7 +18,7 @@ var _ = Describe("utils", func() {
Expect(err).NotTo(HaveOccurred())
})
It("disable some capabilities", func() {
disableCaps := "autoscale,route"
disableCaps := "application"
err := CheckDisabledCapabilities(disableCaps)
Expect(err).NotTo(HaveOccurred())
})