-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into nx-gzip-support
- Loading branch information
Showing
138 changed files
with
5,697 additions
and
3,287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
nfdtopologygarbagecollector "sigs.k8s.io/node-feature-discovery/pkg/nfd-topology-gc" | ||
"sigs.k8s.io/node-feature-discovery/pkg/version" | ||
) | ||
|
||
const ( | ||
// ProgramName is the canonical name of this program | ||
ProgramName = "nfd-topology-gc" | ||
) | ||
|
||
func main() { | ||
flags := flag.NewFlagSet(ProgramName, flag.ExitOnError) | ||
|
||
printVersion := flags.Bool("version", false, "Print version and exit.") | ||
|
||
args := parseArgs(flags, os.Args[1:]...) | ||
|
||
if *printVersion { | ||
fmt.Println(ProgramName, version.Get()) | ||
os.Exit(0) | ||
} | ||
|
||
// Assert that the version is known | ||
if version.Undefined() { | ||
klog.Warningf("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.") | ||
} | ||
|
||
// Get new TopologyGC instance | ||
gc, err := nfdtopologygarbagecollector.New(args) | ||
if err != nil { | ||
klog.Exit(err) | ||
} | ||
|
||
if err = gc.Run(); err != nil { | ||
klog.Exit(err) | ||
} | ||
} | ||
|
||
func parseArgs(flags *flag.FlagSet, osArgs ...string) *nfdtopologygarbagecollector.Args { | ||
args := initFlags(flags) | ||
|
||
_ = flags.Parse(osArgs) | ||
if len(flags.Args()) > 0 { | ||
fmt.Fprintf(flags.Output(), "unknown command line argument: %s\n", flags.Args()[0]) | ||
flags.Usage() | ||
os.Exit(2) | ||
} | ||
|
||
return args | ||
} | ||
|
||
func initFlags(flagset *flag.FlagSet) *nfdtopologygarbagecollector.Args { | ||
args := &nfdtopologygarbagecollector.Args{} | ||
|
||
flagset.DurationVar(&args.GCPeriod, "gc-interval", time.Duration(1)*time.Hour, | ||
"Interval between which Garbage Collector will try to cleanup any missed but already obsolete NodeResourceTopology. [Default: 1h]") | ||
flagset.StringVar(&args.Kubeconfig, "kubeconfig", "", | ||
"Kubeconfig to use") | ||
|
||
klog.InitFlags(flagset) | ||
|
||
return args | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
"time" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestArgsParse(t *testing.T) { | ||
Convey("When parsing command line arguments", t, func() { | ||
flags := flag.NewFlagSet(ProgramName, flag.ExitOnError) | ||
|
||
Convey("When valid -gc-interval is specified", func() { | ||
args := parseArgs(flags, | ||
"-gc-interval=30s") | ||
|
||
Convey("args.GCPeriod is set to appropriate values", func() { | ||
So(args.GCPeriod, ShouldEqual, 30*time.Second) | ||
}) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.