istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/operator/install_test.go (about)

     1  //go:build integ
     2  // +build integ
     3  
     4  // Copyright Istio Authors
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package operator
    19  
    20  import (
    21  	"strings"
    22  	"testing"
    23  
    24  	"istio.io/istio/pkg/test/framework"
    25  	"istio.io/istio/pkg/test/framework/components/istioctl"
    26  	"istio.io/istio/pkg/test/util/assert"
    27  )
    28  
    29  const InvalidRevision = "invalid revision specified"
    30  
    31  type installTestCase struct {
    32  	command   []string
    33  	errString string
    34  }
    35  
    36  // TestInstallCommandInput tests istioctl install command with different input arguments
    37  func TestInstallCommandInput(t *testing.T) {
    38  	framework.
    39  		NewTest(t).
    40  		Run(func(ctx framework.TestContext) {
    41  			istioCtl := istioctl.NewOrFail(ctx, ctx, istioctl.Config{})
    42  			testCases := []installTestCase{
    43  				{
    44  					command:   []string{"install", "--dry-run", "--revision", ""},
    45  					errString: InvalidRevision,
    46  				},
    47  				{
    48  					command:   []string{"install", "--dry-run", "--revision", "1.8.0"},
    49  					errString: InvalidRevision,
    50  				},
    51  				{
    52  					command:   []string{"install", "--dry-run", "--set", "values.global.network=network1"},
    53  					errString: "",
    54  				},
    55  			}
    56  			for _, test := range testCases {
    57  				_, actualError, _ := istioCtl.Invoke(test.command)
    58  				if !strings.Contains(actualError, test.errString) {
    59  					t.Errorf("istioctl install command expects to fail with error message: %s, but got: %s", test.errString, actualError)
    60  				}
    61  			}
    62  		})
    63  }
    64  
    65  func TestReInstallAfterFailure(t *testing.T) {
    66  	framework.NewTest(t).
    67  		Run(func(t framework.TestContext) {
    68  			istioCtl := istioctl.NewOrFail(t, t, istioctl.Config{})
    69  			cs := t.Clusters().Default()
    70  			t.Cleanup(func() {
    71  				cleanupIstioResources(t, cs, istioCtl)
    72  			})
    73  
    74  			// Install with a fake tag to make the installation fail
    75  			_, _, err := istioCtl.Invoke([]string{
    76  				"install", "--skip-confirmation",
    77  				"--set", "tag=0.20.0-faketag",
    78  				"--readiness-timeout", "5s",
    79  			})
    80  			assert.Error(t, err)
    81  
    82  			// Here we should have two activated webhooks, but dry-run should not report any error, which
    83  			// means the re-installation can be done successfully.
    84  			output, outErr := istioCtl.InvokeOrFail(t, []string{"install", "--dry-run"})
    85  			if !strings.Contains(output, "Made this installation the default for cluster-wide operations.") {
    86  				t.Errorf("install expects to succeed but didn't")
    87  			}
    88  			assert.Equal(t, "", outErr)
    89  		})
    90  }