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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ include $(addprefix ./vendor/github.com/openshift/build-machinery-go/make/, \
)

GO_LD_EXTRAFLAGS :=-X k8s.io/component-base/version.gitMajor="1" \
-X k8s.io/component-base/version.gitMinor="21" \
-X k8s.io/component-base/version.gitVersion="v0.21.0-beta.1" \
-X k8s.io/component-base/version.gitMinor="23" \
-X k8s.io/component-base/version.gitVersion="v0.23.0" \
-X k8s.io/component-base/version.gitCommit="$(SOURCE_GIT_COMMIT)" \
-X k8s.io/component-base/version.buildDate="$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
-X k8s.io/component-base/version.gitTreeState="clean" \
Expand Down Expand Up @@ -55,8 +55,7 @@ $(call build-image,ocp-cli,$(IMAGE_REGISTRY)/ocp/4.2:cli,./images/cli/Dockerfile

$(call build-image,ocp-cli-artifacts,$(IMAGE_REGISTRY)/ocp/4.2:cli-artifacts,./images/cli-artifacts/Dockerfile.rhel,.)

# TODO: Temporarily disable golang verification until we get golang-1.17 for rhel7
# $(call verify-golang-versions,images/cli/Dockerfile.rhel)
$(call verify-golang-versions,images/cli/Dockerfile.rhel)

image-ocp-cli-artifacts: image-ocp-cli

Expand Down
22 changes: 22 additions & 0 deletions cmd/oc/flag_value_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import "github.com/spf13/pflag"

// flagValueWrapper delegates all functionality to inner pflag.Value
type flagValueWrapper struct {
inner pflag.Value
}

var _ pflag.Value = new(flagValueWrapper)

func (l *flagValueWrapper) String() string {
return l.inner.String()
}

func (l *flagValueWrapper) Set(value string) error {
return l.inner.Set(value)
}

func (l *flagValueWrapper) Type() string {
return l.inner.Type()
}
30 changes: 7 additions & 23 deletions cmd/oc/oc.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package main

import (
goflag "flag"
"math/rand"
"os"
"path/filepath"
"runtime"
"time"

"github.com/spf13/pflag"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachineryruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
utilflag "k8s.io/component-base/cli/flag"
k8scli "k8s.io/component-base/cli"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
"k8s.io/kubectl/pkg/scheme"

"github.com/openshift/api/apps"
Expand All @@ -42,24 +38,15 @@ import (
)

func injectLoglevelFlag(flags *pflag.FlagSet) {
from := goflag.CommandLine
if flag := from.Lookup("v"); flag != nil {
level := flag.Value.(*klog.Level)
levelPtr := (*int32)(level)
flags.Int32Var(levelPtr, "loglevel", 0, "Set the level of log output (0-10)")
if flags.Lookup("v") == nil {
flags.Int32Var(levelPtr, "v", 0, "Set the level of log output (0-10)")
}
if vFlag := flags.Lookup("v"); vFlag != nil {
flags.Var(&flagValueWrapper{vFlag.Value}, "loglevel", "Set the level of log output (0-10)")
}
}

func main() {
logs.InitLogs()
defer logs.FlushLogs()
defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"), version.Get())()
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()

rand.Seed(time.Now().UTC().UnixNano())
if len(os.Getenv("GOMAXPROCS")) == 0 {
runtime.GOMAXPROCS(runtime.NumCPU())
}
Expand All @@ -68,10 +55,6 @@ func main() {
// See: https://github.com/moby/moby/issues/39859
os.Setenv("MOBY_DISABLE_PIGZ", "true")

pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
injectLoglevelFlag(pflag.CommandLine)

// the kubectl scheme expects to have all the recognizable external types it needs to consume. Install those here.
// We can't use the "normal" scheme because apply will use that to build stategic merge patches on CustomResources
utilruntime.Must(apps.Install(scheme.Scheme))
Expand All @@ -90,9 +73,10 @@ func main() {

basename := filepath.Base(os.Args[0])
command := cli.CommandFor(basename)
if err := command.Execute(); err != nil {
os.Exit(1)
}
logs.AddFlags(command.PersistentFlags())
injectLoglevelFlag(command.PersistentFlags())
code := k8scli.Run(command)
os.Exit(code)
}

func installNonCRDSecurity(scheme *apimachineryruntime.Scheme) error {
Expand Down
Loading