MCPcopy
hub / github.com/kubernetes/kubernetes / fromConfigMap

Method fromConfigMap

cmd/kubeadm/app/componentconfigs/configset.go:73–111  ·  view source on GitHub ↗

fromConfigMap is an utility function, which will load the value of a key of a config map and use h.FromDocumentMap() to perform the parsing This is an utility func. Used by the component config support implementations. Don't use it outside of that context.

(client clientset.Interface, cmName, cmKey string, mustExist bool)

Source from the content-addressed store, hash-verified

71// fromConfigMap is an utility function, which will load the value of a key of a config map and use h.FromDocumentMap() to perform the parsing
72// This is an utility func. Used by the component config support implementations. Don't use it outside of that context.
73func (h *handler) fromConfigMap(client clientset.Interface, cmName, cmKey string, mustExist bool) (kubeadmapi.ComponentConfig, error) {
74 configMap, err := apiclient.GetConfigMapWithShortRetry(client, metav1.NamespaceSystem, cmName)
75 if err != nil {
76 if !mustExist && (apierrors.IsNotFound(err) || apierrors.IsForbidden(err)) {
77 klog.Warningf("Warning: No %s config is loaded. Continuing without it: %v", h.GroupVersion, err)
78 return nil, nil
79 }
80 return nil, err
81 }
82
83 configData, ok := configMap.Data[cmKey]
84 if !ok {
85 return nil, errors.Errorf("unexpected error when reading %s ConfigMap: %s key value pair missing", cmName, cmKey)
86 }
87
88 gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(configData))
89 if err != nil {
90 return nil, err
91 }
92
93 // If the checksum comes up neatly we assume the config was generated
94 generatedConfig := VerifyConfigMapSignature(configMap)
95
96 componentCfg, err := h.FromDocumentMap(gvkmap)
97 if err != nil {
98 // If the config was generated and we get UnsupportedConfigVersionError, we skip loading it.
99 // This will force us to use the generated default current version (effectively regenerating the config with the current version).
100 if _, ok := err.(*UnsupportedConfigVersionError); ok && generatedConfig {
101 return nil, nil
102 }
103 return nil, err
104 }
105
106 if componentCfg != nil {
107 componentCfg.SetUserSupplied(!generatedConfig)
108 }
109
110 return componentCfg, nil
111}
112
113// FromCluster loads a component from a config map in the cluster
114func (h *handler) FromCluster(clientset clientset.Interface, clusterCfg *kubeadmapi.ClusterConfiguration) (kubeadmapi.ComponentConfig, error) {

Callers 3

clusterConfigFromClusterFunction · 0.80
kubeletConfigFromClusterFunction · 0.80

Calls 7

FromDocumentMapMethod · 0.95
ErrorfFunction · 0.92
VerifyConfigMapSignatureFunction · 0.85
IsForbiddenMethod · 0.80
WarningfMethod · 0.80
SetUserSuppliedMethod · 0.65

Tested by 1

clusterConfigFromClusterFunction · 0.64