...

Source file src/sigs.k8s.io/cli-utils/pkg/apply/applier_builder.go

Documentation: sigs.k8s.io/cli-utils/pkg/apply

     1  // Copyright 2021 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package apply
     5  
     6  import (
     7  	"k8s.io/apimachinery/pkg/api/meta"
     8  	"k8s.io/cli-runtime/pkg/resource"
     9  	"k8s.io/client-go/discovery"
    10  	"k8s.io/client-go/dynamic"
    11  	"k8s.io/client-go/rest"
    12  	"k8s.io/kubectl/pkg/cmd/util"
    13  	"sigs.k8s.io/cli-utils/pkg/apply/info"
    14  	"sigs.k8s.io/cli-utils/pkg/apply/prune"
    15  	"sigs.k8s.io/cli-utils/pkg/inventory"
    16  	"sigs.k8s.io/cli-utils/pkg/kstatus/watcher"
    17  )
    18  
    19  type ApplierBuilder struct {
    20  	commonBuilder
    21  }
    22  
    23  // NewApplierBuilder returns a new ApplierBuilder.
    24  func NewApplierBuilder() *ApplierBuilder {
    25  	return &ApplierBuilder{
    26  		// Defaults, if any, go here.
    27  	}
    28  }
    29  
    30  func (b *ApplierBuilder) Build() (*Applier, error) {
    31  	bx, err := b.finalize()
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  	return &Applier{
    36  		pruner: &prune.Pruner{
    37  			InvClient: bx.invClient,
    38  			Client:    bx.client,
    39  			Mapper:    bx.mapper,
    40  		},
    41  		statusWatcher: bx.statusWatcher,
    42  		invClient:     bx.invClient,
    43  		client:        bx.client,
    44  		openAPIGetter: bx.discoClient,
    45  		mapper:        bx.mapper,
    46  		infoHelper:    info.NewHelper(bx.mapper, bx.unstructuredClientForMapping),
    47  	}, nil
    48  }
    49  
    50  func (b *ApplierBuilder) WithFactory(factory util.Factory) *ApplierBuilder {
    51  	b.factory = factory
    52  	return b
    53  }
    54  
    55  func (b *ApplierBuilder) WithInventoryClient(invClient inventory.Client) *ApplierBuilder {
    56  	b.invClient = invClient
    57  	return b
    58  }
    59  
    60  func (b *ApplierBuilder) WithDynamicClient(client dynamic.Interface) *ApplierBuilder {
    61  	b.client = client
    62  	return b
    63  }
    64  
    65  func (b *ApplierBuilder) WithDiscoveryClient(discoClient discovery.CachedDiscoveryInterface) *ApplierBuilder {
    66  	b.discoClient = discoClient
    67  	return b
    68  }
    69  
    70  func (b *ApplierBuilder) WithRestMapper(mapper meta.RESTMapper) *ApplierBuilder {
    71  	b.mapper = mapper
    72  	return b
    73  }
    74  
    75  func (b *ApplierBuilder) WithRestConfig(restConfig *rest.Config) *ApplierBuilder {
    76  	b.restConfig = restConfig
    77  	return b
    78  }
    79  
    80  func (b *ApplierBuilder) WithUnstructuredClientForMapping(unstructuredClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)) *ApplierBuilder {
    81  	b.unstructuredClientForMapping = unstructuredClientForMapping
    82  	return b
    83  }
    84  
    85  func (b *ApplierBuilder) WithStatusWatcher(statusWatcher watcher.StatusWatcher) *ApplierBuilder {
    86  	b.statusWatcher = statusWatcher
    87  	return b
    88  }
    89  

View as plain text