...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/chaosimpl/networkchaos/podnetworkchaosmanager/builder.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/chaosimpl/networkchaos/podnetworkchaosmanager

     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 podnetworkchaosmanager
    17  
    18  import (
    19  	"github.com/go-logr/logr"
    20  	"go.uber.org/fx"
    21  	"k8s.io/apimachinery/pkg/runtime"
    22  	"k8s.io/apimachinery/pkg/types"
    23  	"sigs.k8s.io/controller-runtime/pkg/client"
    24  )
    25  
    26  type Builder struct {
    27  	Log logr.Logger
    28  	client.Client
    29  	client.Reader
    30  	scheme *runtime.Scheme
    31  }
    32  
    33  type Params struct {
    34  	fx.In
    35  
    36  	Logger logr.Logger
    37  	Client client.Client
    38  	Reader client.Reader `name:"no-cache"`
    39  	Scheme *runtime.Scheme
    40  }
    41  
    42  func NewBuilder(params Params) *Builder {
    43  	return &Builder{
    44  		Log:    params.Logger,
    45  		Client: params.Client,
    46  		Reader: params.Reader,
    47  		scheme: params.Scheme,
    48  	}
    49  }
    50  
    51  func (b *Builder) Build(source string, key types.NamespacedName) *PodNetworkManager {
    52  	t := &PodNetworkTransaction{}
    53  
    54  	return &PodNetworkManager{
    55  		Source: source,
    56  		Log:    b.Log,
    57  		Client: b.Client,
    58  		Reader: b.Reader,
    59  		scheme: b.scheme,
    60  
    61  		Key: key,
    62  		T:   t,
    63  	}
    64  }
    65  
    66  func (b *Builder) WithInit(source string, key types.NamespacedName) *PodNetworkManager {
    67  	t := &PodNetworkTransaction{}
    68  	t.Clear(source)
    69  
    70  	return &PodNetworkManager{
    71  		Source: source,
    72  		Log:    b.Log,
    73  		Client: b.Client,
    74  		Reader: b.Reader,
    75  		scheme: b.scheme,
    76  
    77  		Key: key,
    78  		T:   t,
    79  	}
    80  }
    81