...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/podnetworkchaos/fx.go

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

     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  package podnetworkchaos
    17  
    18  import (
    19  	"reflect"
    20  
    21  	"github.com/go-logr/logr"
    22  	ctrl "sigs.k8s.io/controller-runtime"
    23  	"sigs.k8s.io/controller-runtime/pkg/client"
    24  	"sigs.k8s.io/controller-runtime/pkg/event"
    25  	"sigs.k8s.io/controller-runtime/pkg/predicate"
    26  
    27  	"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
    28  	"github.com/chaos-mesh/chaos-mesh/controllers/config"
    29  	"github.com/chaos-mesh/chaos-mesh/controllers/utils/builder"
    30  	"github.com/chaos-mesh/chaos-mesh/controllers/utils/chaosdaemon"
    31  	"github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder"
    32  )
    33  
    34  func Bootstrap(mgr ctrl.Manager, client client.Client, logger logr.Logger, b *chaosdaemon.ChaosDaemonClientBuilder, recorderBuilder *recorder.RecorderBuilder) error {
    35  	if !config.ShouldSpawnController("podnetworkchaos") {
    36  		return nil
    37  	}
    38  
    39  	return builder.Default(mgr).
    40  		For(&v1alpha1.PodNetworkChaos{}).
    41  		Named("podnetworkchaos").
    42  		WithEventFilter(predicate.Funcs{
    43  			UpdateFunc: func(e event.UpdateEvent) bool {
    44  				oldObj := e.ObjectOld.(*v1alpha1.PodNetworkChaos)
    45  				newObj := e.ObjectNew.(*v1alpha1.PodNetworkChaos)
    46  
    47  				return !reflect.DeepEqual(oldObj.Spec, newObj.Spec)
    48  			},
    49  		}).
    50  		Complete(&Reconciler{
    51  			Client:   client,
    52  			Log:      logger.WithName("podnetworkchaos"),
    53  			Recorder: recorderBuilder.Build("podnetworkchaos"),
    54  
    55  			// TODO:
    56  			AllowHostNetworkTesting:  config.ControllerCfg.AllowHostNetworkTesting,
    57  			ChaosDaemonClientBuilder: b,
    58  		})
    59  }
    60