Skip to content

Commit c8c1aea

Browse files
authored
Merge pull request kubernetes#82248 from rosti/proxyless
kubeadm: Fetching kube-proxy's config map is now optional
2 parents 100608f + 31b4c78 commit c8c1aea

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

cmd/kubeadm/app/componentconfigs/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ go_library(
2424
"//pkg/proxy/apis/config:go_default_library",
2525
"//pkg/proxy/apis/config/v1alpha1:go_default_library",
2626
"//pkg/proxy/apis/config/validation:go_default_library",
27+
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
2728
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2829
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
2930
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",

cmd/kubeadm/app/componentconfigs/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package componentconfigs
1818

1919
import (
2020
"github.com/pkg/errors"
21+
"k8s.io/klog"
2122

23+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2224
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325
"k8s.io/apimachinery/pkg/runtime"
2426
"k8s.io/apimachinery/pkg/util/version"
@@ -63,6 +65,13 @@ func GetFromKubeProxyConfigMap(client clientset.Interface, version *version.Vers
6365
// Read the ConfigMap from the cluster
6466
kubeproxyCfg, err := apiclient.GetConfigMapWithRetry(client, metav1.NamespaceSystem, kubeadmconstants.KubeProxyConfigMap)
6567
if err != nil {
68+
// The Kube-Proxy config map may be non-existent, because the user has decided to manage it by themselves
69+
// or to use other proxy solution. It may also be forbidden - if the kube-proxy phase was skipped we have neither
70+
// the config map, nor the RBAC rules allowing join access to it.
71+
if apierrors.IsNotFound(err) || apierrors.IsForbidden(err) {
72+
klog.Warningf("Warning: No kube-proxy config is loaded. Continuing without it: %v", err)
73+
return nil, nil
74+
}
6675
return nil, err
6776
}
6877

cmd/kubeadm/app/componentconfigs/config_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestGetFromConfigMap(t *testing.T) {
4747
component RegistrationKind
4848
configMap *fakeConfigMap
4949
expectedError bool
50+
expectedNil bool
5051
}{
5152
{
5253
name: "valid kube-proxy",
@@ -59,10 +60,10 @@ func TestGetFromConfigMap(t *testing.T) {
5960
},
6061
},
6162
{
62-
name: "invalid kube-proxy - missing ConfigMap",
63-
component: KubeProxyConfigurationKind,
64-
configMap: nil,
65-
expectedError: true,
63+
name: "valid kube-proxy - missing ConfigMap",
64+
component: KubeProxyConfigurationKind,
65+
configMap: nil,
66+
expectedNil: true,
6667
},
6768
{
6869
name: "invalid kube-proxy - missing key",
@@ -123,8 +124,8 @@ func TestGetFromConfigMap(t *testing.T) {
123124
return
124125
}
125126

126-
if obj == nil {
127-
t.Error("unexpected nil return value")
127+
if rt.expectedNil != (obj == nil) {
128+
t.Error("unexpected return value")
128129
}
129130
})
130131
}

cmd/kubeadm/app/util/config/cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ func getComponentConfigs(client clientset.Interface, clusterConfiguration *kubea
203203
return err
204204
}
205205

206+
// Some components may not be installed or managed by kubeadm, hence GetFromConfigMap won't return an error or an object
207+
if obj == nil {
208+
continue
209+
}
210+
206211
if ok := registration.SetToInternalConfig(obj, clusterConfiguration); !ok {
207212
return errors.Errorf("couldn't save componentconfig value for kind %q", string(kind))
208213
}

cmd/kubeadm/app/util/config/cluster_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ func TestGetComponentConfigs(t *testing.T) {
449449
},
450450
},
451451
},
452-
expectedError: true,
453452
},
454453
}
455454

@@ -483,9 +482,6 @@ func TestGetComponentConfigs(t *testing.T) {
483482
if cfg.ComponentConfigs.Kubelet == nil {
484483
t.Errorf("invalid cfg.ComponentConfigs.Kubelet")
485484
}
486-
if cfg.ComponentConfigs.KubeProxy == nil {
487-
t.Errorf("invalid cfg.ComponentConfigs.KubeProxy")
488-
}
489485
})
490486
}
491487
}

0 commit comments

Comments
 (0)