...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/pipeline/steps.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/pipeline

     1  // Copyright 2021 Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package pipeline
    15  
    16  import (
    17  	"sigs.k8s.io/controller-runtime/pkg/reconcile"
    18  
    19  	"github.com/chaos-mesh/chaos-mesh/controllers/condition"
    20  	"github.com/chaos-mesh/chaos-mesh/controllers/desiredphase"
    21  	"github.com/chaos-mesh/chaos-mesh/controllers/finalizers"
    22  	"github.com/chaos-mesh/chaos-mesh/controllers/records"
    23  )
    24  
    25  func ConditionStep(ctx *PipelineContext) reconcile.Reconciler {
    26  	setupLog := ctx.Logger.WithName("setup-condition")
    27  	name := ctx.Object.Name + "-condition"
    28  	setupLog.Info("setting up controller", "name", name)
    29  
    30  	return &condition.Reconciler{
    31  		Object:   ctx.Object.Object,
    32  		Client:   ctx.Client,
    33  		Recorder: ctx.Mgr.GetEventRecorderFor("condition"),
    34  		Log:      ctx.Logger.WithName("condition"),
    35  	}
    36  }
    37  
    38  func DesiredPhaseStep(ctx *PipelineContext) reconcile.Reconciler {
    39  	setupLog := ctx.Logger.WithName("setup-desiredphase")
    40  	name := ctx.Object.Name + "-desiredphase"
    41  
    42  	setupLog.Info("setting up controller", "name", name)
    43  
    44  	return &desiredphase.Reconciler{
    45  		Object:   ctx.Object.Object,
    46  		Client:   ctx.Client,
    47  		Recorder: ctx.RecorderBuilder.Build("desiredphase"),
    48  		Log:      ctx.Logger.WithName("desiredphase"),
    49  	}
    50  }
    51  
    52  func FinalizersStep(ctx *PipelineContext) reconcile.Reconciler {
    53  	setupLog := ctx.Logger.WithName("setup-finalizers")
    54  	name := ctx.Object.Name + "-finalizers"
    55  
    56  	setupLog.Info("setting up controller", "name", name)
    57  
    58  	return &finalizers.Reconciler{
    59  		Object:   ctx.Object.Object,
    60  		Client:   ctx.Client,
    61  		Recorder: ctx.RecorderBuilder.Build("finalizers"),
    62  		Log:      ctx.Logger.WithName("finalizers"),
    63  	}
    64  }
    65  
    66  func RecordsStep(ctx *PipelineContext) reconcile.Reconciler {
    67  	return &records.Reconciler{
    68  		Impl:     ctx.Impl,
    69  		Object:   ctx.Object.Object,
    70  		Client:   ctx.Client,
    71  		Reader:   ctx.Reader,
    72  		Recorder: ctx.RecorderBuilder.Build("records"),
    73  		Selector: ctx.Selector,
    74  		Log:      ctx.Logger.WithName("records"),
    75  	}
    76  }
    77  
    78  func AllSteps() []PipelineStep {
    79  	return []PipelineStep{FinalizersStep, DesiredPhaseStep, ConditionStep, RecordsStep}
    80  }
    81