...

Source file src/helm.sh/helm/v3/pkg/action/status.go

Documentation: helm.sh/helm/v3/pkg/action

     1  /*
     2  Copyright The Helm Authors.
     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  package action
    18  
    19  import (
    20  	"bytes"
    21  	"errors"
    22  
    23  	"helm.sh/helm/v3/pkg/kube"
    24  	"helm.sh/helm/v3/pkg/release"
    25  )
    26  
    27  // Status is the action for checking the deployment status of releases.
    28  //
    29  // It provides the implementation of 'helm status'.
    30  type Status struct {
    31  	cfg *Configuration
    32  
    33  	Version int
    34  
    35  	// If true, display description to output format,
    36  	// only affect print type table.
    37  	// TODO Helm 4: Remove this flag and output the description by default.
    38  	ShowDescription bool
    39  
    40  	// ShowResources sets if the resources should be retrieved with the status.
    41  	// TODO Helm 4: Remove this flag and output the resources by default.
    42  	ShowResources bool
    43  
    44  	// ShowResourcesTable is used with ShowResources. When true this will cause
    45  	// the resulting objects to be retrieved as a kind=table.
    46  	ShowResourcesTable bool
    47  }
    48  
    49  // NewStatus creates a new Status object with the given configuration.
    50  func NewStatus(cfg *Configuration) *Status {
    51  	return &Status{
    52  		cfg: cfg,
    53  	}
    54  }
    55  
    56  // Run executes 'helm status' against the given release.
    57  func (s *Status) Run(name string) (*release.Release, error) {
    58  	if err := s.cfg.KubeClient.IsReachable(); err != nil {
    59  		return nil, err
    60  	}
    61  
    62  	if !s.ShowResources {
    63  		return s.cfg.releaseContent(name, s.Version)
    64  	}
    65  
    66  	rel, err := s.cfg.releaseContent(name, s.Version)
    67  	if err != nil {
    68  		return nil, err
    69  	}
    70  
    71  	if kubeClient, ok := s.cfg.KubeClient.(kube.InterfaceResources); ok {
    72  		var resources kube.ResourceList
    73  		if s.ShowResourcesTable {
    74  			resources, err = kubeClient.BuildTable(bytes.NewBufferString(rel.Manifest), false)
    75  			if err != nil {
    76  				return nil, err
    77  			}
    78  		} else {
    79  			resources, err = s.cfg.KubeClient.Build(bytes.NewBufferString(rel.Manifest), false)
    80  			if err != nil {
    81  				return nil, err
    82  			}
    83  		}
    84  
    85  		resp, err := kubeClient.Get(resources, true)
    86  		if err != nil {
    87  			return nil, err
    88  		}
    89  
    90  		rel.Info.Resources = resp
    91  
    92  		return rel, nil
    93  	}
    94  	return nil, errors.New("unable to get kubeClient with interface InterfaceResources")
    95  }
    96  

View as plain text