Проблема с аутентификацией и glog не распечатывает логи - PullRequest
0 голосов
/ 25 января 2019

Я пытаюсь написать отдельную программу для аутентификации пользователя.Я хочу увидеть, что происходит за кулисами в коде openshift, так как моя аутентификация иногда срабатывает, а иногда не проходит.Также, как я могу получить ошибку, которую я получаю от openshift.В LoginOptions есть атрибуты Out и ErrOut, но я не знаю, как их использовать

Версия: 3.9.0

glide.yaml

package: openshift-application
import:
- package: github.com/golang/glog
- package: github.com/docker/distribution
  repo:    https://github.com/openshift/docker-distribution
  version: release-2.6.0
- package: k8s.io/kube-openapi
  version: 39a7bf85c140f972372c2a0d1ee40adbf0c8bfe1
- package: k8s.io/code-generator
  repo:    https://github.com/openshift/kubernetes-code-generator
  version: release-1.9.1
- package: k8s.io/apimachinery
  repo:    https://github.com/openshift/kubernetes-apimachinery
  version: release-1.9.1
- package: k8s.io/api
  repo:    https://github.com/openshift/kubernetes-api
  version: release-1.9.1
- package: k8s.io/client-go
  repo:    https://github.com/openshift/kubernetes-client-go
  version: release-1.9.1
- package: k8s.io/metrics
  repo:    https://github.com/openshift/kubernetes-metrics
  version: release-1.9.1
- package: k8s.io/apiserver
  repo:    https://github.com/openshift/kubernetes-apiserver
  version: release-1.9.1
- package: k8s.io/kube-aggregator
  repo:    https://github.com/openshift/kube-aggregator
  version: release-1.9.1
- package: k8s.io/apiextensions-apiserver
  repo:    https://github.com/openshift/kubernetes-apiextensions-apiserver
  version: release-1.9.1
- package: k8s.io/kubernetes
  repo:    https://github.com/openshift/kubernetes
  version: release-1.9.1
# openshift second
- package: github.com/openshift/api
  version: release-3.9
- package: github.com/openshift/client-go
  version: release-3.9
# this is pinned because it doesn't have branches
- package: github.com/openshift/imagebuilder
  version: eeb3c28f366cd654c136204f4ab8221593b0e899
- package: github.com/openshift/origin
  version: v3.9.0
  subpackages: 
  - pkg/oc/cli/cmd/login
  - pkg/oc/cli/cmd
  - pkg/oc/admin/project
  - pkg/authorization/generated/internalclientset
  - pkg/client/config
  - pkg/cmd/server/bootstrappolicy
  - pkg/user/generated/internalclientset/typed/user/internalversion
- package: github.com/chai2010/gettext-go/gettext
- package: github.com/davecgh/go-spew/spew

test.go file

package main
import (
    //"io"
    //"fmt"
    //"io/ioutil"
    "github.com/golang/glog"
    "github.com/spf13/pflag"
    "k8s.io/client-go/tools/clientcmd"
    "github.com/openshift/origin/pkg/client/config"
    "github.com/openshift/origin/pkg/oc/cli/cmd/login"
    //kcmdconfig "k8s.io/kubernetes/pkg/kubectl/cmd/config"
    //kclientcmdapi "k8s.io/client-go/tools/clientcmd/api"
    "github.com/davecgh/go-spew/spew"
)

func main() {
    println("Inside the main function")
    username := "**********"
    password := "**********"
    server := "https://master.na39.openshift.opentlc.com"
    loginOptions := newLoginOptions(server, username, password, true)
    if err := loginOptions.GatherInfo(); err != nil {
        spew.Dump(loginOptions)
        panic(err)
    }

    if loginOptions.Username != "himanshu_gupta01-infosys.com" {
        glog.Fatalf("Unexpected user after authentication: %s", loginOptions)
    } else {
        println("Passed")
        //println(loginOptions.BearerToken)
        spew.Dump(loginOptions)
    }
    glog.Flush()
}
func newLoginOptions(server string, username string, password string, insecure bool) *login.LoginOptions {
    flagset := pflag.NewFlagSet("test-flags", pflag.ContinueOnError)
    flags := []string{}
    clientConfig := defaultClientConfig(flagset)
    flagset.Parse(flags)

    startingConfig, _ := clientConfig.RawConfig()
    loginOptions := &login.LoginOptions{
        Server:             server,
        StartingKubeConfig: &startingConfig,
        Username:           username,
        Password:           password,
        InsecureTLS:        insecure,
    }
    glog.Flush()
    return loginOptions
}


func defaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
    loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: ""}

    flags.StringVar(&loadingRules.ExplicitPath, config.OpenShiftConfigFlagName, "", "Path to the config file to use for CLI requests.")

    overrides := &clientcmd.ConfigOverrides{}
    overrideFlags := clientcmd.RecommendedConfigOverrideFlags("")
    overrideFlags.ContextOverrideFlags.Namespace.ShortName = "n"
    clientcmd.BindOverrideFlags(overrides, flags, overrideFlags)

    clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides)

    return clientConfig
}

Испытанные команды:

go run test.go -v=10 -vmodule=*=10 -logtostderr
go run test.go -v=10 --vmodule=*=10 --logtostderr
...