Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit c4f1ef5

Browse files
authored
Merge pull request #107 from resouer/fix-log
Fix log-dir and create path
2 parents bae746f + 1ca46a2 commit c4f1ef5

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

cmd/frakti/frakti.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"github.com/golang/glog"
2424
"github.com/spf13/pflag"
2525

26-
"k8s.io/apiserver/pkg/util/flag"
2726
"k8s.io/frakti/pkg/alternativeruntime"
2827
"k8s.io/frakti/pkg/hyper"
2928
"k8s.io/frakti/pkg/manager"
29+
"k8s.io/frakti/pkg/util/flags"
3030
"k8s.io/frakti/pkg/util/logs"
3131
"k8s.io/kubernetes/pkg/kubelet/server/streaming"
3232
)
@@ -59,7 +59,7 @@ var (
5959
)
6060

6161
func main() {
62-
flag.InitFlags()
62+
flags.InitFlags()
6363
logs.InitLogs()
6464
defer logs.FlushLogs()
6565

pkg/util/flags/flags.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2017 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+
goflag "flag"
21+
"os"
22+
"strings"
23+
24+
"github.com/golang/glog"
25+
"github.com/spf13/pflag"
26+
)
27+
28+
var (
29+
// these are flags from vendored cadvisor
30+
hiddenVendorFlags = []string{
31+
"boot-id-file",
32+
"container-hints",
33+
"docker",
34+
"docker-env-metadata-whitelist",
35+
"docker-only",
36+
"docker-root",
37+
"event-storage-age-limit",
38+
"event-storage-event-limit",
39+
"global-housekeeping-interval",
40+
"housekeeping-interval",
41+
"log-cadvisor-usage",
42+
"machine-id-file",
43+
"stderrthreshold",
44+
"storage-driver-buffer-duration",
45+
"storage-driver-db ",
46+
"storage-driver-host",
47+
"storage-driver-password",
48+
"storage-driver-secure",
49+
"storage-driver-table",
50+
"storage-driver-user",
51+
"vmodule",
52+
}
53+
)
54+
55+
// WordSepNormalizeFunc changes all flags that contain "_" separators
56+
func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
57+
if strings.Contains(name, "_") {
58+
return pflag.NormalizedName(strings.Replace(name, "_", "-", -1))
59+
}
60+
return pflag.NormalizedName(name)
61+
}
62+
63+
// WarnWordSepNormalizeFunc changes and warns for flags that contain "_" separators
64+
func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
65+
if strings.Contains(name, "_") {
66+
nname := strings.Replace(name, "_", "-", -1)
67+
glog.Warningf("%s is DEPRECATED and will be removed in a future version. Use %s instead.", name, nname)
68+
69+
return pflag.NormalizedName(nname)
70+
}
71+
return pflag.NormalizedName(name)
72+
}
73+
74+
// InitFlags normalizes and parses the command line flags
75+
func InitFlags() {
76+
pflag.CommandLine.SetNormalizeFunc(WordSepNormalizeFunc)
77+
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
78+
79+
for _, hiddenFlag := range hiddenVendorFlags {
80+
pflag.CommandLine.MarkHidden(hiddenFlag)
81+
}
82+
83+
pflag.Parse()
84+
85+
path := pflag.Lookup("log-dir").Value.String()
86+
if _, err := os.Stat(path); os.IsNotExist(err) {
87+
os.MkdirAll(path, 0755)
88+
}
89+
}

0 commit comments

Comments
 (0)