Change:
From in The most important things I want to see through node e2e tests: 1) the kubelet is started from last-known-good-config file 2) kubelet can download the new config properly to the node; and restart itself from the new config file 3) kubelet can mark the config bad properly after several round of crashing caused the bad config 4) Kubelet can roll back the last-known-good-config and restart itself from that good one 5) kubelet can properly reports its configuration status Note: (2) is covered by existing e2enode tests (1, 4, 5) were covered by the , all of which I plan to turn into automated tests after this PR merges - but I'm trying not to increase the size of this PR any further ~(3) we need to figure out how to test this. I don't want to rely on a "valid" config that causes a crash loop - because the very existence of such a config should be viewed as a bug. I also don't want to include a "please crash loop for our tests" field in the config, because that's an ugly API. The best solution is not clear here.~ We decided to remove crash-loop detection, see . Filing this issue to track this work: into e2e_node tests [x] remote config [x] local (from file) config [x] ~test the crash-loop detection~ removed, see above /cc
[MILESTONENOTIFIER] Milestone Removed Important: This issue was missing labels required for the v1.8 milestone for more than 7 days: kind: Must specify exactly one of [, , ]. priority: Must specify exactly one of [, , ]. Removing it from the milestone. <detailsAdditional instructions available <a href=""here</aThe commands available for adding these labels are documented <a href=""here</a</details
Issues go stale after 90d of inactivity. Mark the issue as fresh with . Stale issues rot after an additional 30d of inactivity and eventually close. Prevent issues from auto-closing with an comment. If this issue is safe to close now please do so with . Send feedback to sig-testing, kubernetes/test-infra and/or . /lifecycle stale
/remove-lifecycle stale
The test cases in the OP have been covered by our e2e_node tests for a while.

Discussion:
load( "@io_bazel_rules_go//go:def.bzl", "go_library", <ins> "go_test", </ins> ) go_library(

srcs = [":package-srcs"], tags = ["automanaged"], ) <ins> go_test( name = "go_default_test", srcs = ["configfiles_test.go"], library = ":go_default_library", deps = [ "//pkg/kubelet/apis/kubeletconfig:go_default_library", "//pkg/kubelet/apis/kubeletconfig/scheme:go_default_library", "//pkg/kubelet/apis/kubeletconfig/v1alpha1:go_default_library", "//pkg/kubelet/kubeletconfig/util/files:go_default_library", "//pkg/kubelet/kubeletconfig/util/filesystem:go_default_library", "//pkg/kubelet/kubeletconfig/util/test:go_default_library", "//vendor/github.com/davecgh/go-spew/spew:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", ], ) </ins>

utilfs "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/filesystem" ) <ins> const kubeletFile = "kubelet" </ins> // Loader loads configuration from a storage layer type Loader interface { // Load loads and returns the KubeletConfiguration from the storage layer, or an error if a configuration could not be loaded

configDir string } <del> // NewFSLoader returns a Loader that loads a KubeletConfiguration from the files in `configDir` func NewFSLoader(fs utilfs.Filesystem, configDir string) (Loader, error) { </del> <ins> // NewFsLoader returns a Loader that loads a KubeletConfiguration from the files in `configDir` func NewFsLoader(fs utilfs.Filesystem, configDir string) (Loader, error) { </ins> _, kubeletCodecs, err := kubeletscheme.NewSchemeAndCodecs() if err != nil { return nil, err

} func (loader *fsLoader) Load() (*kubeletconfig.KubeletConfiguration, error) { <del> errfmt := fmt.Sprintf("failed to load Kubelet config files from %q, error: ", loader.configDir) + "%v" </del> // require the config be in a file called "kubelet" <del> path := filepath.Join(loader.configDir, "kubelet") </del> <ins> path := filepath.Join(loader.configDir, kubeletFile) </ins> data, err := loader.fs.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read init config file %q, error: %v", path, err)

// no configuration is an error, some parameters are required if len(data) == 0 { <del> return nil, fmt.Errorf(errfmt, fmt.Errorf("config file was empty, but some parameters are required")) </del> <ins> return nil, fmt.Errorf("init config file %q was empty, but some parameters are required", path) </ins> } return utilcodec.DecodeKubeletConfiguration(loader.kubeletCodecs, data)

<ins> /* Copyright 2017 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 configfiles import ( "fmt" "path/filepath" "strings" "testing" "github.com/davecgh/go-spew/spew" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig" kubeletscheme "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme" kubeletconfigv1alpha1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1alpha1" utilfiles "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files" utilfs "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/filesystem" utiltest "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test" ) func addFile(fs utilfs.Filesystem, path string, file string) error { if err := utilfiles.EnsureDir(fs, filepath.Dir(path)); err != nil { return err } if err := utilfiles.ReplaceFile(fs, path, []byte(file)); err != nil { return err } return nil } func TestLoad(t *testing.T) { kubeletScheme, _, err := kubeletscheme.NewSchemeAndCodecs() if err != nil { t.Fatalf("unexpected error: %v", err) } // get the built-in default configuration external := &kubeletconfigv1alpha1.KubeletConfiguration{} kubeletScheme.Default(external) defaultConfig := &kubeletconfig.KubeletConfiguration{} err = kubeletScheme.Convert(external, defaultConfig, nil) if err != nil { t.Fatalf("unexpected error: %v", err) } cases := []struct { desc   string file   string expect *kubeletconfig.KubeletConfiguration err    string }{ {"empty data", ``, nil, "was empty"}, // invalid format {"invalid yaml", `*`, nil, "failed to decode"}, {"invalid json", `{*`, nil, "failed to decode"}, // invalid object {"missing kind", `{"apiVersion":"kubeletconfig/v1alpha1"}`, nil, "failed to decode"}, {"missing version", `{"kind":"KubeletConfiguration"}`, nil, "failed to decode"}, {"unregistered kind", `{"kind":"BogusKind","apiVersion":"kubeletconfig/v1alpha1"}`, nil, "failed to decode"}, {"unregistered version", `{"kind":"KubeletConfiguration","apiVersion":"bogusversion"}`, nil, "failed to decode"}, // empty object with correct kind and version should result in the defaults for that kind and version {"default from yaml", `kind: KubeletConfiguration apiVersion: kubeletconfig/v1alpha1`, defaultConfig, ""}, {"default from json", `{"kind":"KubeletConfiguration","apiVersion":"kubeletconfig/v1alpha1"}`, defaultConfig, ""}, } fs := utilfs.NewFakeFs() for i := range cases { dir := fmt.Sprintf("/%d", i) if err := addFile(fs, filepath.Join(dir, kubeletFile), cases[i].file); err != nil { t.Fatalf("unexpected error: %v", err) } loader, err := NewFsLoader(fs, dir) if err != nil { t.Fatalf("unexpected error: %v", err) } kc, err := loader.Load() if utiltest.SkipRest(t, cases[i].desc, err, cases[i].err) { continue } // we expect the parsed configuration to match what we described in the ConfigMap if !apiequality.Semantic.DeepEqual(cases[i].expect, kc) { t.Errorf("case %q, expect config %s but got %s", cases[i].desc, spew.Sdump(cases[i].expect), spew.Sdump(kc)) } } // finally test for a missing file desc := "missing kubelet file" contains := "failed to read" loader, err := NewFsLoader(fs, "/fake") if err != nil { t.Fatalf("unexpected error: %v", err) } _, err = loader.Load() if err == nil { t.Errorf("case %q, expect error to contain %q but got nil error", desc, contains) } else if !strings.Contains(err.Error(), contains) { t.Errorf("case %q, expect error to contain %q but got %q", desc, contains, err.Error()) } } </ins>

var initLoader configfiles.Loader if len(initConfigDir) > 0 { <del> initLoader, err = configfiles.NewFSLoader(fs, initConfigDir) </del> <ins> initLoader, err = configfiles.NewFsLoader(fs, initConfigDir) </ins> if err != nil { return nil, err }