...

Source file src/helm.sh/helm/v3/pkg/action/get_metadata.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 "time"
    20  
    21  // GetMetadata is the action for checking a given release's metadata.
    22  //
    23  // It provides the implementation of 'helm get metadata'.
    24  type GetMetadata struct {
    25  	cfg *Configuration
    26  
    27  	Version int
    28  }
    29  
    30  type Metadata struct {
    31  	Name       string `json:"name" yaml:"name"`
    32  	Chart      string `json:"chart" yaml:"chart"`
    33  	Version    string `json:"version" yaml:"version"`
    34  	AppVersion string `json:"appVersion" yaml:"appVersion"`
    35  	Namespace  string `json:"namespace" yaml:"namespace"`
    36  	Revision   int    `json:"revision" yaml:"revision"`
    37  	Status     string `json:"status" yaml:"status"`
    38  	DeployedAt string `json:"deployedAt" yaml:"deployedAt"`
    39  }
    40  
    41  // NewGetMetadata creates a new GetMetadata object with the given configuration.
    42  func NewGetMetadata(cfg *Configuration) *GetMetadata {
    43  	return &GetMetadata{
    44  		cfg: cfg,
    45  	}
    46  }
    47  
    48  // Run executes 'helm get metadata' against the given release.
    49  func (g *GetMetadata) Run(name string) (*Metadata, error) {
    50  	if err := g.cfg.KubeClient.IsReachable(); err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	rel, err := g.cfg.releaseContent(name, g.Version)
    55  	if err != nil {
    56  		return nil, err
    57  	}
    58  
    59  	return &Metadata{
    60  		Name:       rel.Name,
    61  		Chart:      rel.Chart.Metadata.Name,
    62  		Version:    rel.Chart.Metadata.Version,
    63  		AppVersion: rel.Chart.Metadata.AppVersion,
    64  		Namespace:  rel.Namespace,
    65  		Revision:   rel.Version,
    66  		Status:     rel.Info.Status.String(),
    67  		DeployedAt: rel.Info.LastDeployed.Format(time.RFC3339),
    68  	}, nil
    69  }
    70  

View as plain text