Skip to content

Commit 8249804

Browse files
committed
add pkg/flags directory for kubelet dev purposes and go mod tidy/vendor
Signed-off-by: Jason Cho <[email protected]>
1 parent 8b3c0a1 commit 8249804

File tree

3,654 files changed

+1240884
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,654 files changed

+1240884
-0
lines changed

go.mod

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module github.com/IBM/power-dra-driver
2+
3+
go 1.23.3
4+
5+
require (
6+
github.com/spf13/pflag v1.0.6
7+
github.com/urfave/cli/v2 v2.27.5
8+
k8s.io/apimachinery v0.32.1
9+
k8s.io/client-go v0.32.1
10+
k8s.io/component-base v0.32.1
11+
)
12+
13+
require (
14+
github.com/beorn7/perks v1.0.1 // indirect
15+
github.com/blang/semver/v4 v4.0.0 // indirect
16+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
17+
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
18+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
19+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
20+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
21+
github.com/go-logr/logr v1.4.2 // indirect
22+
github.com/go-logr/zapr v1.3.0 // indirect
23+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
24+
github.com/go-openapi/jsonreference v0.20.2 // indirect
25+
github.com/go-openapi/swag v0.23.0 // indirect
26+
github.com/gogo/protobuf v1.3.2 // indirect
27+
github.com/golang/protobuf v1.5.4 // indirect
28+
github.com/google/gnostic-models v0.6.8 // indirect
29+
github.com/google/go-cmp v0.6.0 // indirect
30+
github.com/google/gofuzz v1.2.0 // indirect
31+
github.com/google/uuid v1.6.0 // indirect
32+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
33+
github.com/josharian/intern v1.0.0 // indirect
34+
github.com/json-iterator/go v1.1.12 // indirect
35+
github.com/mailru/easyjson v0.7.7 // indirect
36+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
37+
github.com/modern-go/reflect2 v1.0.2 // indirect
38+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
39+
github.com/pkg/errors v0.9.1 // indirect
40+
github.com/prometheus/client_golang v1.19.1 // indirect
41+
github.com/prometheus/client_model v0.6.1 // indirect
42+
github.com/prometheus/common v0.55.0 // indirect
43+
github.com/prometheus/procfs v0.15.1 // indirect
44+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
45+
github.com/spf13/cobra v1.8.1 // indirect
46+
github.com/x448/float16 v0.8.4 // indirect
47+
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
48+
go.opentelemetry.io/otel v1.28.0 // indirect
49+
go.opentelemetry.io/otel/trace v1.28.0 // indirect
50+
go.uber.org/multierr v1.11.0 // indirect
51+
go.uber.org/zap v1.27.0 // indirect
52+
golang.org/x/net v0.30.0 // indirect
53+
golang.org/x/oauth2 v0.23.0 // indirect
54+
golang.org/x/sys v0.26.0 // indirect
55+
golang.org/x/term v0.25.0 // indirect
56+
golang.org/x/text v0.19.0 // indirect
57+
golang.org/x/time v0.7.0 // indirect
58+
google.golang.org/protobuf v1.35.1 // indirect
59+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
60+
gopkg.in/inf.v0 v0.9.1 // indirect
61+
gopkg.in/yaml.v3 v3.0.1 // indirect
62+
k8s.io/api v0.32.1 // indirect
63+
k8s.io/klog/v2 v2.130.1 // indirect
64+
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
65+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
66+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
67+
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
68+
sigs.k8s.io/yaml v1.4.0 // indirect
69+
)

go.sum

Lines changed: 196 additions & 0 deletions
Large diffs are not rendered by default.

pkg/flags/kubeclient.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2023 The Kubernetes Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package flags
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/urfave/cli/v2"
23+
24+
coreclientset "k8s.io/client-go/kubernetes"
25+
"k8s.io/client-go/rest"
26+
"k8s.io/client-go/tools/clientcmd"
27+
)
28+
29+
type KubeClientConfig struct {
30+
KubeConfig string
31+
KubeAPIQPS float64
32+
KubeAPIBurst int
33+
}
34+
35+
type ClientSets struct {
36+
Core coreclientset.Interface
37+
}
38+
39+
func (k *KubeClientConfig) Flags() []cli.Flag {
40+
flags := []cli.Flag{
41+
&cli.StringFlag{
42+
Category: "Kubernetes client:",
43+
Name: "kubeconfig",
44+
Usage: "Absolute path to the `KUBECONFIG` file. Either this flag or the KUBECONFIG env variable need to be set if the driver is being run out of cluster.",
45+
Destination: &k.KubeConfig,
46+
EnvVars: []string{"KUBECONFIG"},
47+
},
48+
&cli.Float64Flag{
49+
Category: "Kubernetes client:",
50+
Name: "kube-api-qps",
51+
Usage: "`QPS` to use while communicating with the Kubernetes apiserver.",
52+
Value: 5,
53+
Destination: &k.KubeAPIQPS,
54+
EnvVars: []string{"KUBE_API_QPS"},
55+
},
56+
&cli.IntFlag{
57+
Category: "Kubernetes client:",
58+
Name: "kube-api-burst",
59+
Usage: "`Burst` to use while communicating with the Kubernetes apiserver.",
60+
Value: 10,
61+
Destination: &k.KubeAPIBurst,
62+
EnvVars: []string{"KUBE_API_BURST"},
63+
},
64+
}
65+
66+
return flags
67+
}
68+
69+
func (k *KubeClientConfig) NewClientSetConfig() (*rest.Config, error) {
70+
var csconfig *rest.Config
71+
72+
var err error
73+
if k.KubeConfig == "" {
74+
csconfig, err = rest.InClusterConfig()
75+
if err != nil {
76+
return nil, fmt.Errorf("create in-cluster client configuration: %v", err)
77+
}
78+
} else {
79+
csconfig, err = clientcmd.BuildConfigFromFlags("", k.KubeConfig)
80+
if err != nil {
81+
return nil, fmt.Errorf("create out-of-cluster client configuration: %v", err)
82+
}
83+
}
84+
85+
csconfig.QPS = float32(k.KubeAPIQPS)
86+
csconfig.Burst = k.KubeAPIBurst
87+
88+
return csconfig, nil
89+
}
90+
91+
func (k *KubeClientConfig) NewClientSets() (ClientSets, error) {
92+
csconfig, err := k.NewClientSetConfig()
93+
if err != nil {
94+
return ClientSets{}, fmt.Errorf("create client configuration: %v", err)
95+
}
96+
97+
coreclient, err := coreclientset.NewForConfig(csconfig)
98+
if err != nil {
99+
return ClientSets{}, fmt.Errorf("create core client: %v", err)
100+
}
101+
102+
return ClientSets{
103+
Core: coreclient,
104+
}, nil
105+
}

pkg/flags/logging.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2023 The Kubernetes Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package flags
18+
19+
import (
20+
"strings"
21+
22+
"github.com/spf13/pflag"
23+
"github.com/urfave/cli/v2"
24+
25+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
26+
"k8s.io/component-base/featuregate"
27+
logsapi "k8s.io/component-base/logs/api/v1"
28+
29+
_ "k8s.io/component-base/logs/json/register" // for JSON log output support
30+
)
31+
32+
type LoggingConfig struct {
33+
featureGate featuregate.MutableFeatureGate
34+
config *logsapi.LoggingConfiguration
35+
}
36+
37+
func NewLoggingConfig() *LoggingConfig {
38+
fg := featuregate.NewFeatureGate()
39+
var _ pflag.Value = fg // compile-time check for the type conversion below
40+
l := &LoggingConfig{
41+
featureGate: fg,
42+
config: logsapi.NewLoggingConfiguration(),
43+
}
44+
utilruntime.Must(logsapi.AddFeatureGates(l.featureGate))
45+
utilruntime.Must(l.featureGate.SetFromMap(map[string]bool{string(logsapi.ContextualLogging): true}))
46+
return l
47+
}
48+
49+
// Apply should be called in a cli.App.Before directly after parsing command
50+
// line flags and before running any code which emits log entries.
51+
func (l *LoggingConfig) Apply() error {
52+
return logsapi.ValidateAndApply(l.config, l.featureGate)
53+
}
54+
55+
// Flags returns the flags for the configuration.
56+
func (l *LoggingConfig) Flags() []cli.Flag {
57+
var fs pflag.FlagSet
58+
logsapi.AddFlags(l.config, &fs)
59+
60+
// Adding the feature gates flag to fs means that its going to be added
61+
// with "logging" as category. In practice, the logging code is the
62+
// only code which uses the flag, therefore that seems like a good
63+
// place to report it.
64+
fs.AddFlag(&pflag.Flag{
65+
Name: "feature-gates",
66+
Usage: "A set of key=value pairs that describe feature gates for alpha/experimental features. " +
67+
"Options are:\n " + strings.Join(l.featureGate.KnownFeatures(), "\n "),
68+
Value: l.featureGate.(pflag.Value), //nolint:forcetypeassert // No need for type check: l.featureGate is a *featuregate.featureGate, which implements pflag.Value.
69+
})
70+
71+
var flags []cli.Flag
72+
fs.VisitAll(func(flag *pflag.Flag) {
73+
flags = append(flags, pflagToCLI(flag, "Logging:"))
74+
})
75+
return flags
76+
}
77+
78+
func pflagToCLI(flag *pflag.Flag, category string) cli.Flag {
79+
return &cli.GenericFlag{
80+
Name: flag.Name,
81+
Category: category,
82+
Usage: flag.Usage,
83+
Value: flag.Value,
84+
Destination: flag.Value,
85+
EnvVars: []string{strings.ToUpper(strings.ReplaceAll(flag.Name, "-", "_"))},
86+
}
87+
}

vendor/github.com/beorn7/perks/LICENSE

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)