Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,13 @@ data:
{{- end }}
{{- end }}

{{- if not (eq .Values.revision "") }}
{{- $defPilotHostname := printf "istiod-%s.%s.svc" .Values.revision .Release.Namespace }}
{{- else }}
{{- $defPilotHostname := printf "istiod.%s.svc" .Release.Namespace }}
{{- end }}
{{- $defPilotHostname := printf "istiod%s.%s.svc" .Values.revision .Release.Namespace }}
{{- $pilotAddress := .Values.global.remotePilotAddress | default $defPilotHostname }}

# controlPlaneAuthPolicy is for mounted secrets, will wait for the files.
controlPlaneAuthPolicy: NONE
discoveryAddress: {{ $pilotAddress }}:15012

{{- if .Values.global.remotePilotAddress }}
discoveryAddress: {{ .Values.global.remotePilotAddress }}
{{- else }}
discoveryAddress: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{.Release.Namespace}}.svc:15012
{{- end }}

{{- if .Values.global.proxy.envoyMetricsService.enabled }}
#
Expand Down
4 changes: 2 additions & 2 deletions operator/cmd/mesh/manifest-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func ApplyManifests(setOverlay []string, inFilenames []string, force bool, dryRu
if err != nil {
return err
}
manifests, _, err := GenManifests(inFilenames, ysf, force, kubeconfig, l)
manifests, iop, err := GenManifests(inFilenames, ysf, force, kubeconfig, l)
if err != nil {
return fmt.Errorf("failed to generate manifest: %v", err)
}
Expand All @@ -136,7 +136,7 @@ func ApplyManifests(setOverlay []string, inFilenames []string, force bool, dryRu
manifests[cn] = append(manifests[cn], fmt.Sprintf("# %s component has been deprecated.\n", cn))
}

out, err := manifest.ApplyAll(manifests, version.OperatorBinaryVersion, opts)
out, err := manifest.ApplyAll(manifests, version.OperatorBinaryVersion, iop.Revision, opts)
if err != nil {
return fmt.Errorf("failed to apply manifest with kubectl client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion operator/cmd/mesh/operator-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func applyManifest(manifestStr, componentName string, opts *kubectlcmd.Options,
l.logAndPrint("")
// Specifically don't prune operator installation since it leads to a lot of resources being reapplied.
opts.Prune = pointer.BoolPtr(false)
out, objs := manifest.ApplyManifest(name.ComponentName(componentName), manifestStr, version.OperatorBinaryVersion.String(), *opts)
out, objs := manifest.ApplyManifest(name.ComponentName(componentName), manifestStr, version.OperatorBinaryVersion.String(), "", *opts)

if opts.Wait {
err := manifest.WaitForResources(objs, opts)
Expand Down
2 changes: 1 addition & 1 deletion operator/data/translateConfig/translateConfig-1.5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apiMapping:
MeshConfig.rootNamespace:
outPath: "global.istioNamespace"
Revision:
outPath: "global.revision"
outPath: "revision"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path was wrong before

kubernetesMapping:
"Components.{{.ComponentName}}.K8S.Affinity":
outPath: "[{{.ResourceType}}:{{.ResourceName}}].spec.template.spec.affinity"
Expand Down
2 changes: 1 addition & 1 deletion operator/data/translateConfig/translateConfig-1.6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apiMapping:
MeshConfig.rootNamespace:
outPath: "global.istioNamespace"
Revision:
outPath: "global.revision"
outPath: "revision"
kubernetesMapping:
"Components.{{.ComponentName}}.K8S.Affinity":
outPath: "[{{.ResourceType}}:{{.ResourceName}}].spec.template.spec.affinity"
Expand Down
18 changes: 13 additions & 5 deletions operator/pkg/manifest/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"

"istio.io/istio/pilot/pkg/model"

// For GCP auth functionality.
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -264,7 +266,7 @@ func parseKubectlVersion(kubectlStdout string) (*goversion.Version, *goversion.V
}

// ApplyAll applies all given manifests using kubectl client.
func ApplyAll(manifests name.ManifestMap, version pkgversion.Version, opts *kubectlcmd.Options) (CompositeOutput, error) {
func ApplyAll(manifests name.ManifestMap, version pkgversion.Version, revision string, opts *kubectlcmd.Options) (CompositeOutput, error) {
scope.Infof("Preparing manifests for these components:")
for c := range manifests {
scope.Infof("- %s", c)
Expand All @@ -273,10 +275,10 @@ func ApplyAll(manifests name.ManifestMap, version pkgversion.Version, opts *kube
if _, err := InitK8SRestClient(opts.Kubeconfig, opts.Context); err != nil {
return nil, err
}
return applyRecursive(manifests, version, opts)
return applyRecursive(manifests, version, revision, opts)
}

func applyRecursive(manifests name.ManifestMap, version pkgversion.Version, opts *kubectlcmd.Options) (CompositeOutput, error) {
func applyRecursive(manifests name.ManifestMap, version pkgversion.Version, revision string, opts *kubectlcmd.Options) (CompositeOutput, error) {
var wg sync.WaitGroup
var mu sync.Mutex
out := CompositeOutput{}
Expand All @@ -291,7 +293,7 @@ func applyRecursive(manifests name.ManifestMap, version pkgversion.Version, opts
<-s
scope.Infof("Prerequisite for %s has completed, proceeding with install.", c)
}
applyOut, appliedObjects := ApplyManifest(c, strings.Join(m, helm.YAMLSeparator), version.String(), *opts)
applyOut, appliedObjects := ApplyManifest(c, strings.Join(m, helm.YAMLSeparator), version.String(), revision, *opts)
mu.Lock()
out[c] = applyOut
allAppliedObjects = append(allAppliedObjects, appliedObjects...)
Expand Down Expand Up @@ -321,7 +323,7 @@ func applyRecursive(manifests name.ManifestMap, version pkgversion.Version, opts
return out, nil
}

func ApplyManifest(componentName name.ComponentName, manifestStr, version string,
func ApplyManifest(componentName name.ComponentName, manifestStr, version, revision string,
opts kubectlcmd.Options) (*ComponentApplyOutput, object.K8sObjects) {
stdout, stderr := "", ""
appliedObjects := object.K8sObjects{}
Expand All @@ -330,6 +332,9 @@ func ApplyManifest(componentName name.ComponentName, manifestStr, version string
return buildComponentApplyOutput(stdout, stderr, appliedObjects, err), appliedObjects
}
componentLabel := fmt.Sprintf("%s=%s", istioComponentLabelStr, componentName)
if revision != "" {
componentLabel += fmt.Sprintf(",%s=%s", model.RevisionLabel, revision)
}

// TODO: remove this when `kubectl --prune` supports empty objects
// (https://github.com/kubernetes/kubernetes/issues/40635)
Expand Down Expand Up @@ -376,6 +381,9 @@ func ApplyManifest(componentName name.ComponentName, manifestStr, version string
o.AddLabels(map[string]string{istioComponentLabelStr: string(componentName)})
o.AddLabels(map[string]string{operatorLabelStr: operatorReconcileStr})
o.AddLabels(map[string]string{istioVersionLabelStr: version})
if revision != "" {
o.AddLabels(map[string]string{model.RevisionLabel: revision})
}
}

opts.ExtraArgs = []string{"--force", "--selector", componentLabel}
Expand Down
19 changes: 7 additions & 12 deletions operator/pkg/vfs/assets.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pkg/test/framework/components/istio/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

var (
dummyValidationRule = `
dummyValidationRuleTemplate = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
Expand All @@ -40,8 +40,7 @@ spec:
)

func waitForValidationWebhook(accessor *kube.Accessor, cfg Config) error {
dummyValidationRule = fmt.Sprintf(dummyValidationRule, cfg.SystemNamespace)

dummyValidationRule := fmt.Sprintf(dummyValidationRuleTemplate, cfg.SystemNamespace)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we call this twice it would fmt.Sprintf twice

defer func() {
e := accessor.DeleteContents("", dummyValidationRule)
if e != nil {
Expand Down
12 changes: 7 additions & 5 deletions pkg/test/framework/components/namespace/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sync"
"time"

"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/test/framework/components/environment/kube"
"istio.io/istio/pkg/test/framework/components/istio"
"istio.io/istio/pkg/test/framework/resource"
Expand Down Expand Up @@ -112,8 +113,8 @@ func claimKube(ctx resource.Context, name string) (Instance, error) {

if !env.Accessor.NamespaceExists(name) {
nsConfig := Config{
Inject: true,
CustomInjectorNamespace: cfg.CustomSidecarInjectorNamespace,
Inject: true,
Revision: cfg.CustomSidecarInjectorNamespace,
}
nsLabels := createNamespaceLabels(&nsConfig)
if err := env.CreateNamespaceWithLabels(name, "istio-test", nsLabels); err != nil {
Expand Down Expand Up @@ -151,9 +152,10 @@ func newKube(ctx resource.Context, nsConfig *Config) (Instance, error) {
func createNamespaceLabels(cfg *Config) map[string]string {
l := make(map[string]string)
if cfg.Inject {
l["istio-injection"] = "enabled"
if cfg.CustomInjectorNamespace != "" {
l["istio-env"] = cfg.CustomInjectorNamespace
if cfg.Revision != "" {
l[model.RevisionLabel] = cfg.Revision
} else {
l["istio-injection"] = "enabled"
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/test/framework/components/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

// Config contains configuration information about the namespace instance
type Config struct {
Prefix string // prefix to use for autogenerated namespace name
Inject bool // whether to add sidecar injection label to this namespace
CustomInjectorNamespace string // namespace of custom injector instance
Labels map[string]string // arbitrary labels to be applied to namespace
Prefix string // prefix to use for autogenerated namespace name
Inject bool // whether to add sidecar injection label to this namespace
Revision string // namespace of custom injector instance
Labels map[string]string // arbitrary labels to be applied to namespace
}

// Instance represents an allocated namespace that can be used to create config, or deploy components in.
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/pilot/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ func TestMain(m *testing.M) {
framework.
NewSuite("pilot_test", m).
SetupOnEnv(environment.Kube, istio.Setup(&i, nil)).
SetupOnEnv(environment.Kube, istio.Setup(&i, func(cfg *istio.Config) {
cfg.ControlPlaneValues = `
components:
base:
enabled: false
pilot:
enabled: true
ingressGateways:
addonComponents:
prometheus:
enabled: false
revision: canary
values:
clusterResources: false
`
})).
Setup(func(ctx resource.Context) (err error) {
if g, err = galley.New(ctx, galley.Config{}); err != nil {
return err
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/pilot/revisions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2020 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package pilot

import (
"testing"
"time"

"istio.io/istio/pkg/test/framework"
"istio.io/istio/pkg/test/framework/components/echo"
"istio.io/istio/pkg/test/framework/components/echo/echoboot"
"istio.io/istio/pkg/test/framework/components/namespace"
"istio.io/istio/pkg/test/util/retry"
)

// TestMultiRevision Sets up a simple client -> server call, where the client and server
// belong to different control planes.
func TestMultiRevision(t *testing.T) {
framework.NewTest(t).
Run(func(ctx framework.TestContext) {
stable := namespace.NewOrFail(t, ctx, namespace.Config{
Prefix: "stable",
Inject: true,
})
canary := namespace.NewOrFail(t, ctx, namespace.Config{
Prefix: "canary",
Inject: true,
Revision: "canary",
})

var client, server echo.Instance
echoboot.NewBuilderOrFail(t, ctx).
With(&client, echoConfig(stable, "client")).
With(&server, echoConfig(canary, "server")).
BuildOrFail(t)
retry.UntilSuccessOrFail(t, func() error {
resp, err := client.Call(echo.CallOptions{
Target: server,
PortName: "http",
})
if err != nil {
return err
}
return resp.CheckOK()
}, retry.Delay(time.Millisecond*100))
})
}