Skip to content

Commit

Permalink
Merge branch 'master' into nx-gzip-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandan-Abhyankar authored Jan 12, 2023
2 parents 3cddfd1 + 497e6c7 commit 0ea6447
Show file tree
Hide file tree
Showing 138 changed files with 5,697 additions and 3,287 deletions.
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/new-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Please do not remove items from the checklist
`git branch release-0.$MAJ master`
- [ ] An OWNER pushes the new release branch with
`git push release-0.$MAJ`
- [ ] Create Prow pre-submit job configuration for the new release branch in K8s
[test-infra](https://github.com/kubernetes/test-infra), submit a PR
- [ ] Wait for the test-infra Prow config PR to be merged
- [ ] Run `hack/prepare-release.sh $VERSION` to turn references to point to the upcoming release
(README, deployment templates, docs configuration, test/e2e flags), submit a PR against the release branch
- An OWNER prepares a draft release
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG BASE_IMAGE_MINIMAL
FROM ${BUILDER_IMAGE} as builder

# Build and install the grpc-health-probe binary
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.6 && \
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.14 && \
go install github.com/grpc-ecosystem/grpc-health-probe@${GRPC_HEALTH_PROBE_VERSION} \
# Rename it as it's referenced as grpc_health_probe in the deployment yamls
# and in its own project https://github.com/grpc-ecosystem/grpc-health-probe
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else
endif
HOSTMOUNT_PREFIX ?= /

KUBECONFIG ?=
KUBECONFIG ?= ${HOME}/.kube/config
E2E_TEST_CONFIG ?=
E2E_PULL_IF_NOT_PRESENT ?= false

Expand Down Expand Up @@ -119,12 +119,20 @@ templates:
@# Need to prepend each line in the sample config with spaces in order to
@# fit correctly in the configmap spec.
@sed s'/^/ /' deployment/components/worker-config/nfd-worker.conf.example > nfd-worker.conf.tmp
@sed s'/^/ /' deployment/components/topology-updater-config/nfd-topology-updater.conf.example > nfd-topology-updater.conf.tmp
@# The sed magic below replaces the block of text between the lines with start and end markers
@start=NFD-WORKER-CONF-START-DO-NOT-REMOVE; \
end=NFD-WORKER-CONF-END-DO-NOT-REMOVE; \
sed -e "/$$start/,/$$end/{ /$$start/{ p; r nfd-worker.conf.tmp" \
-e "}; /$$end/p; d }" -i deployment/helm/node-feature-discovery/values.yaml
@start=NFD-TOPOLOGY-UPDATER-CONF-START-DO-NOT-REMOVE; \
end=NFD-TOPOLOGY-UPDATER-CONF-END-DO-NOT-REMOVE; \
sed -e "/$$start/,/$$end/{ /$$start/{ p; r nfd-topology-updater.conf.tmp" \
-e "}; /$$end/p; d }" -i deployment/helm/node-feature-discovery/values.yaml
@rm nfd-worker.conf.tmp
@rm nfd-topology-updater.conf.tmp



.generator.image.stamp: Dockerfile_generator
$(IMAGE_BUILD_CMD) \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ features and system configuration!
#### Quick-start – the short-short version

```bash
$ kubectl apply -k https://github.com/kubernetes-sigs/node-feature-discovery/deployment/overlays/default?ref=v0.11.3
$ kubectl apply -k https://github.com/kubernetes-sigs/node-feature-discovery/deployment/overlays/default?ref=v0.12.0
namespace/node-feature-discovery created
customresourcedefinition.apiextensions.k8s.io/nodefeaturerules.nfd.k8s-sigs.io created
serviceaccount/nfd-master created
Expand Down
18 changes: 16 additions & 2 deletions cmd/nfd-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func main() {
os.Exit(2)
}

// Check deprecated flags
flags.Visit(func(f *flag.Flag) {
switch f.Name {
case "featurerules-controller":
klog.Warningf("-featurerules-controller is deprecated, use '-crd-controller' flag instead")
}
})

if *printVersion {
fmt.Println(ProgramName, version.Get())
os.Exit(0)
Expand Down Expand Up @@ -94,10 +102,16 @@ func initFlags(flagset *flag.FlagSet) *master.Args {
flagset.Var(&args.LabelWhiteList, "label-whitelist",
"Regular expression to filter label names to publish to the Kubernetes API server. "+
"NB: the label namespace is omitted i.e. the filter is only applied to the name part after '/'.")
flagset.BoolVar(&args.EnableNodeFeatureApi, "enable-nodefeature-api", false,
"Enable the NodeFeature CRD API for receiving node features. This will automatically disable the gRPC communication.")
flagset.BoolVar(&args.NoPublish, "no-publish", false,
"Do not publish feature labels")
flagset.BoolVar(&args.FeatureRulesController, "featurerules-controller", true,
"Enable controller for NodeFeatureRule objects. Generates node labels based on the rules in these CRs.")
flagset.BoolVar(&args.EnableTaints, "enable-taints", false,
"Enable node tainting feature")
flagset.BoolVar(&args.CrdController, "featurerules-controller", true,
"Enable NFD CRD API controller. DEPRECATED: use -crd-controller instead")
flagset.BoolVar(&args.CrdController, "crd-controller", true,
"Enable NFD CRD API controller for processing NodeFeature and NodeFeatureRule objects.")
flagset.IntVar(&args.Port, "port", 8080,
"Port on which to listen for connections.")
flagset.BoolVar(&args.Prune, "prune", false,
Expand Down
88 changes: 88 additions & 0 deletions cmd/nfd-topology-gc/main.go
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
}
41 changes: 41 additions & 0 deletions cmd/nfd-topology-gc/main_test.go
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)
})
})

})
}
68 changes: 47 additions & 21 deletions cmd/nfd-topology-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@ package main
import (
"flag"
"fmt"
"net/url"
"os"
"time"

"k8s.io/klog/v2"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"

"sigs.k8s.io/node-feature-discovery/pkg/kubeconf"
topology "sigs.k8s.io/node-feature-discovery/pkg/nfd-client/topology-updater"
topology "sigs.k8s.io/node-feature-discovery/pkg/nfd-topology-updater"
"sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor"
"sigs.k8s.io/node-feature-discovery/pkg/topologypolicy"
"sigs.k8s.io/node-feature-discovery/pkg/utils"
"sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath"
"sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf"
"sigs.k8s.io/node-feature-discovery/pkg/version"
)

const (
// ProgramName is the canonical name of this program
ProgramName = "nfd-topology-updater"
ProgramName = "nfd-topology-updater"
kubeletSecurePort = 10250
)

func main() {
Expand All @@ -58,18 +61,38 @@ func main() {
// Plug klog into grpc logging infrastructure
utils.ConfigureGrpcKlog()

klConfig, err := kubeconf.GetKubeletConfigFromLocalFile(resourcemonitorArgs.KubeletConfigFile)
u, err := url.ParseRequestURI(resourcemonitorArgs.KubeletConfigURI)
if err != nil {
klog.Exitf("error reading kubelet config: %v", err)
klog.Exitf("failed to parse args for kubelet-config-uri: %v", err)
}

// init kubelet API client
var klConfig *kubeletconfigv1beta1.KubeletConfiguration
switch u.Scheme {
case "file":
klConfig, err = kubeconf.GetKubeletConfigFromLocalFile(u.Path)
if err != nil {
klog.Exitf("failed to read kubelet config: %v", err)
}
case "https":
restConfig, err := kubeconf.InsecureConfig(u.String(), resourcemonitorArgs.APIAuthTokenFile)
if err != nil {
klog.Exitf("failed to initialize rest config for kubelet config uri: %v", err)
}

klConfig, err = kubeconf.GetKubeletConfiguration(restConfig)
if err != nil {
klog.Exitf("failed to get kubelet config from configz endpoint: %v", err)
}
default:
klog.Exitf("unsupported URI scheme: %v", u.Scheme)
}

tmPolicy := string(topologypolicy.DetectTopologyPolicy(klConfig.TopologyManagerPolicy, klConfig.TopologyManagerScope))
klog.Infof("detected kubelet Topology Manager policy %q", tmPolicy)

// Get new TopologyUpdater instance
instance, err := topology.NewTopologyUpdater(*args, *resourcemonitorArgs, tmPolicy)
if err != nil {
klog.Exitf("failed to initialize TopologyUpdater instance: %v", err)
}
instance := topology.NewTopologyUpdater(*args, *resourcemonitorArgs, tmPolicy)

if err = instance.Run(); err != nil {
klog.Exit(err)
Expand All @@ -86,19 +109,22 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) (*topology.Args, *resource
os.Exit(2)
}

if len(resourcemonitorArgs.KubeletConfigURI) == 0 {
if len(utils.NodeName()) == 0 {
fmt.Fprintf(flags.Output(), "unable to determine the default kubelet config endpoint 'https://${NODE_NAME}:%d/configz' due to empty NODE_NAME environment, "+
"please either define the NODE_NAME environment variable or specify endpoint with the -kubelet-config-uri flag\n", kubeletSecurePort)
os.Exit(1)
}
resourcemonitorArgs.KubeletConfigURI = fmt.Sprintf("https://%s:%d/configz", utils.NodeName(), kubeletSecurePort)
}

return args, resourcemonitorArgs
}

func initFlags(flagset *flag.FlagSet) (*topology.Args, *resourcemonitor.Args) {
args := &topology.Args{}
resourcemonitorArgs := &resourcemonitor.Args{}

flagset.StringVar(&args.CaFile, "ca-file", "",
"Root certificate for verifying connections")
flagset.StringVar(&args.CertFile, "cert-file", "",
"Certificate used for authenticating connections")
flagset.StringVar(&args.KeyFile, "key-file", "",
"Private key matching -cert-file")
flagset.BoolVar(&args.Oneshot, "oneshot", false,
"Update once and exit")
flagset.BoolVar(&args.NoPublish, "no-publish", false,
Expand All @@ -109,14 +135,14 @@ func initFlags(flagset *flag.FlagSet) (*topology.Args, *resourcemonitor.Args) {
"Time to sleep between CR updates. Non-positive value implies no CR updatation (i.e. infinite sleep). [Default: 60s]")
flagset.StringVar(&resourcemonitorArgs.Namespace, "watch-namespace", "*",
"Namespace to watch pods (for testing/debugging purpose). Use * for all namespaces.")
flagset.StringVar(&resourcemonitorArgs.KubeletConfigFile, "kubelet-config-file", hostpath.VarDir.Path("lib/kubelet/config.yaml"),
"Kubelet config file path.")
flagset.StringVar(&resourcemonitorArgs.KubeletConfigURI, "kubelet-config-uri", "",
"Kubelet config URI path. Default to kubelet configz endpoint.")
flagset.StringVar(&resourcemonitorArgs.APIAuthTokenFile, "api-auth-token-file", "/var/run/secrets/kubernetes.io/serviceaccount/token",
"API auth token file path. It is used to request kubelet configz endpoint, only takes effect when kubelet-config-uri is https. Default to /var/run/secrets/kubernetes.io/serviceaccount/token.")
flagset.StringVar(&resourcemonitorArgs.PodResourceSocketPath, "podresources-socket", hostpath.VarDir.Path("lib/kubelet/pod-resources/kubelet.sock"),
"Pod Resource Socket path to use.")
flagset.StringVar(&args.Server, "server", "localhost:8080",
"NFD server address to connecto to.")
flagset.StringVar(&args.ServerNameOverride, "server-name-override", "",
"Hostname expected from server certificate, useful in testing")
flagset.StringVar(&args.ConfigFile, "config", "/etc/kubernetes/node-feature-discovery/nfd-topology-updater.conf",
"Config file to use.")

klog.InitFlags(flagset)

Expand Down
Loading

0 comments on commit 0ea6447

Please sign in to comment.