github.com/imran-kn/cilium-fork@v1.6.9/pkg/client/config.go (about)

     1  // Copyright 2016-2017 Authors of Cilium
     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  package client
    16  
    17  import (
    18  	"github.com/cilium/cilium/api/v1/client/daemon"
    19  	"github.com/cilium/cilium/api/v1/models"
    20  	"github.com/cilium/cilium/pkg/api"
    21  )
    22  
    23  // ConfigGet returns a daemon configuration.
    24  func (c *Client) ConfigGet() (*models.DaemonConfiguration, error) {
    25  	resp, err := c.Daemon.GetConfig(nil)
    26  	if err != nil {
    27  		return nil, Hint(err)
    28  	}
    29  	return resp.Payload, nil
    30  }
    31  
    32  // ConfigPatch modifies the daemon configuration.
    33  func (c *Client) ConfigPatch(cfg models.DaemonConfigurationSpec) error {
    34  	fullCfg, err := c.ConfigGet()
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	for opt, value := range cfg.Options {
    40  		fullCfg.Spec.Options[opt] = value
    41  	}
    42  	if cfg.PolicyEnforcement != "" {
    43  		fullCfg.Spec.PolicyEnforcement = cfg.PolicyEnforcement
    44  	}
    45  
    46  	params := daemon.NewPatchConfigParams().WithConfiguration(fullCfg.Spec).WithTimeout(api.ClientTimeout)
    47  	_, err = c.Daemon.PatchConfig(params)
    48  	return Hint(err)
    49  }