...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/helm/helm_client_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/helm

     1  // Copyright 2022 Chaos Mesh Authors.
     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  
    16  //go:build integration
    17  
    18  package helm
    19  
    20  import (
    21  	"context"
    22  	"fmt"
    23  	"os"
    24  
    25  	"helm.sh/helm/v3/pkg/cli"
    26  
    27  	"github.com/chaos-mesh/chaos-mesh/pkg/log"
    28  )
    29  
    30  func ExampleHelmClient_InstallRelease() {
    31  	chart, err := FetchChaosMeshChart(context.Background(), "2.2.0")
    32  	if err != nil {
    33  		panic(err)
    34  	}
    35  
    36  	settings := cli.New()
    37  	restClientGetter := settings.RESTClientGetter()
    38  	logger, err := log.NewDefaultZapLogger()
    39  	if err != nil {
    40  		panic(err)
    41  	}
    42  	client, err := NewHelmClient(restClientGetter, logger)
    43  	if err != nil {
    44  		panic(err)
    45  	}
    46  	_, err = client.InstallRelease(
    47  		"chaos-mesh",
    48  		"chaos-mesh-in-remote-cluster",
    49  		chart,
    50  		nil,
    51  	)
    52  	if err != nil {
    53  		panic(err)
    54  	}
    55  	// Output:
    56  }
    57  
    58  func ExampleHelmClient_UpgradeRelease() {
    59  	chart, err := FetchChaosMeshChart(context.Background(), "2.5.0")
    60  	if err != nil {
    61  		panic(err)
    62  	}
    63  
    64  	settings := cli.New()
    65  	restClientGetter := settings.RESTClientGetter()
    66  	logger, err := log.NewDefaultZapLogger()
    67  	if err != nil {
    68  		panic(err)
    69  	}
    70  	client, err := NewHelmClient(restClientGetter, logger)
    71  	if err != nil {
    72  		panic(err)
    73  	}
    74  	_, err = client.UpgradeRelease(
    75  		"chaos-mesh",
    76  		"chaos-mesh-in-remote-cluster",
    77  		chart,
    78  		nil,
    79  	)
    80  	if err != nil {
    81  		panic(err)
    82  	}
    83  	// Output:
    84  }
    85  
    86  func ExampleHelmClient_GetRelease() {
    87  	settings := cli.New()
    88  	restClientGetter := settings.RESTClientGetter()
    89  	logger, err := log.NewDefaultZapLogger()
    90  	if err != nil {
    91  		panic(err)
    92  	}
    93  	client, err := NewHelmClient(restClientGetter, logger)
    94  	if err != nil {
    95  		panic(err)
    96  	}
    97  	release, err := client.GetRelease(
    98  		"chaos-mesh",
    99  		"chaos-mesh-in-remote-cluster",
   100  	)
   101  	if err != nil {
   102  		panic(err)
   103  	}
   104  	fmt.Fprintln(os.Stderr, release.Name)
   105  	// Output:
   106  }
   107  
   108  func ExampleHelmClient_UninstallRelease() {
   109  	settings := cli.New()
   110  	restClientGetter := settings.RESTClientGetter()
   111  	logger, err := log.NewDefaultZapLogger()
   112  	if err != nil {
   113  		panic(err)
   114  	}
   115  	client, err := NewHelmClient(restClientGetter, logger)
   116  	if err != nil {
   117  		panic(err)
   118  	}
   119  	_, err = client.UninstallRelease(
   120  		"chaos-mesh",
   121  		"chaos-mesh-in-remote-cluster",
   122  	)
   123  	if err != nil {
   124  		panic(err)
   125  	}
   126  	// Output:
   127  }
   128