Skip to content

Commit

Permalink
Fix stuff, add debug print
Browse files Browse the repository at this point in the history
  • Loading branch information
barchw committed Dec 12, 2024
1 parent 9ffab9b commit 5ecb6c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate-integration-test-manifest: manifests kustomize module-version
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default -o tests/integration/steps/operator_generated_manifest.yaml
yq eval '(.spec.template.spec.containers[0].env //= []) += {"name": "DEBUG_PRINT_IOP", "value": "true"}' -i my-app-deployment.yaml

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
28 changes: 24 additions & 4 deletions cmd/istio-install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package main

import (
"flag"
"fmt"
istioclient "github.com/kyma-project/istio/operator/internal/reconciliations/istio"
"os"
"time"
Expand All @@ -14,8 +16,24 @@ import (
"k8s.io/client-go/rest"
)

type arrayFlags []string

// String is an implementation of the flag.Value interface
func (i *arrayFlags) String() string {
return fmt.Sprintf("%v", *i)
}

// Set is an implementation of the flag.Value interface
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}

func main() {
iopFileNames := []string{os.Args[1]}
var iopFileNamesFlag arrayFlags
flag.Var(&iopFileNamesFlag, "iop-file", "IstioOperator CR file to apply")
debugPrintIopFlag := flag.Bool("debug-print-iop", false, "Print IstioOperator CR content")
flag.Parse()

consoleLogger := istioclient.CreateIstioLibraryLogger()

Expand Down Expand Up @@ -46,17 +64,19 @@ func main() {
os.Exit(1)
}

for _, name := range iopFileNames {
for _, name := range iopFileNamesFlag {
iop, err := os.ReadFile(name)
if err != nil {
consoleLogger.LogAndError("Failed to read IstioOperator CR file: ", err)
os.Exit(1)
}
consoleLogger.LogAndPrintf("Applying IstioOperator CR %s", string(iop))
if *debugPrintIopFlag {
consoleLogger.LogAndPrintf("Applying IstioOperator CR %s", string(iop))
}
}

// We don't want to verify after installation, because it is unreliable
installArgs := &istio.InstallArgs{ReadinessTimeout: 150 * time.Second, SkipConfirmation: true, Verify: false, InFilenames: iopFileNames}
installArgs := &istio.InstallArgs{ReadinessTimeout: 150 * time.Second, SkipConfirmation: true, Verify: false, InFilenames: iopFileNamesFlag}

if err := istio.Install(cliClient, &istio.RootArgs{}, installArgs, os.Stdout, consoleLogger, printer); err != nil {
consoleLogger.LogAndError("Istio install error: ", err)
Expand Down
14 changes: 12 additions & 2 deletions internal/reconciliations/istio/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ type IstioClient struct {
printer istio.Printer
}

const logScope = "istio-library"
const (
debugPrintIopFlag = "-debug-print-iop"
debugPrintIopEnv = "DEBUG_PRINT_IOP"

iopFileNamesFlag = "-iop-file"
logScope = "istio-library"
)

func CreateIstioLibraryLogger() *clog.ConsoleLogger {
registeredScope := istiolog.RegisterScope(logScope, logScope)
Expand All @@ -45,7 +51,11 @@ func installIstioInExternalProcess(mergedIstioOperatorPath string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*6)
defer cancel()

cmd := exec.CommandContext(ctx, istioInstallPath, mergedIstioOperatorPath)
cmd := exec.CommandContext(ctx, istioInstallPath, iopFileNamesFlag, mergedIstioOperatorPath)
if os.Getenv(debugPrintIopEnv) == "true" {
cmd = exec.CommandContext(ctx, istioInstallPath, iopFileNamesFlag, mergedIstioOperatorPath, debugPrintIopFlag)
}

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
Expand Down
10 changes: 8 additions & 2 deletions internal/restarter/sidecars.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package restarter
import (
"context"
"fmt"
"google.golang.org/protobuf/types/known/structpb"
"strings"

"github.com/kyma-project/istio/operator/internal/compatibility"
Expand Down Expand Up @@ -68,7 +67,14 @@ func (s *SidecarsRestarter) Restart(ctx context.Context, istioCR *v1alpha2.Istio
return described_errors.NewDescribedError(err, "Could not get Istio version from istio operator file"), false
}

expectedImage := pods.NewSidecarImage(iop.Spec.Hub, iop.Spec.Tag.(*structpb.Value).GetStringValue())
tag, ok := iop.Spec.Tag.(string)
if !ok {
ctrl.Log.Error(err, "Error getting Istio tag from istio operator file")
s.StatusHandler.SetCondition(istioCR, v1alpha2.NewReasonWithMessage(v1alpha2.ConditionReasonProxySidecarRestartFailed))
return described_errors.NewDescribedError(err, "Could not get Istio tag from istio operator file"), false
}

expectedImage := pods.NewSidecarImage(iop.Spec.Hub, tag)
s.Log.Info("Running proxy sidecar reset", "expected image", expectedImage)

err = gatherer.VerifyIstioPodsVersion(ctx, s.Client, istioImageVersion.Version())
Expand Down

0 comments on commit 5ecb6c3

Please sign in to comment.