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)
| 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. |
| 73 | func (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 |
| 114 | func (h *handler) FromCluster(clientset clientset.Interface, clusterCfg *kubeadmapi.ClusterConfiguration) (kubeadmapi.ComponentConfig, error) { |