github.com/SUSE/skuba@v1.4.17/pkg/skuba/actions/addon/refresh/localconfig.go (about)

     1  /*
     2   * Copyright (c) 2020 SUSE LLC.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   */
    17  
    18  package refresh
    19  
    20  import (
    21  	"fmt"
    22  
    23  	"github.com/pkg/errors"
    24  	clientset "k8s.io/client-go/kubernetes"
    25  
    26  	"github.com/SUSE/skuba/internal/pkg/skuba/addons"
    27  	"github.com/SUSE/skuba/internal/pkg/skuba/kubeadm"
    28  )
    29  
    30  // AddonsBaseManifest implements the `skuba addon refresh localconfig` command.
    31  func AddonsBaseManifest(client clientset.Interface) error {
    32  	currentClusterVersion, err := kubeadm.GetCurrentClusterVersion(client)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	clusterConfiguration, err := kubeadm.GetClusterConfiguration(client)
    38  	if err != nil {
    39  		return errors.Wrap(err, "Could not fetch cluster configuration")
    40  	}
    41  
    42  	// re-render all addons manifest
    43  	addonConfiguration := addons.AddonConfiguration{
    44  		ClusterVersion: currentClusterVersion,
    45  		ControlPlane:   clusterConfiguration.ControlPlaneEndpoint,
    46  		ClusterName:    clusterConfiguration.ClusterName,
    47  	}
    48  	for addonName, addon := range addons.Addons {
    49  		if !addon.IsPresentForClusterVersion(currentClusterVersion) {
    50  			continue
    51  		}
    52  		if err := addon.Write(addonConfiguration); err != nil {
    53  			return errors.Wrapf(err, "failed to refresh addon %s manifest", string(addonName))
    54  		}
    55  	}
    56  
    57  	fmt.Println("Successfully refreshed addons base manifests")
    58  	return nil
    59  }