MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / MigrateConfigFromConfigMap

Function MigrateConfigFromConfigMap

pkg/config/migrate.go:33–68  ·  view source on GitHub ↗
(client crclient.Client)

Source from the content-addressed store, hash-verified

31)
32
33func MigrateConfigFromConfigMap(client crclient.Client) error {
34 migratedConfig, err := convertConfigMapToConfigCRD(client)
35 if err != nil {
36 return err
37 }
38 if migratedConfig == nil {
39 return nil
40 }
41
42 namespace, err := infrastructure.GetNamespace()
43 if err != nil {
44 return err
45 }
46 clusterConfig, err := getClusterConfig(namespace, client)
47 if err != nil {
48 return err
49 }
50 if clusterConfig != nil {
51 // Check using DeepDerivative in case cluster config contains default/additional values -- we only care
52 // that values in migratedConfig are propagated to the cluster DWOC.
53 if equality.Semantic.DeepDerivative(migratedConfig.Config, clusterConfig.Config) {
54 log.Info("Found deprecated operator configmap matching config custom resource. Deleting.")
55 // In case we migrated before but failed to delete
56 return deleteMigratedConfigmap(client)
57 }
58 return fmt.Errorf("found both DevWorkspaceOperatorConfig and configmap on cluster -- cannot migrate")
59 }
60
61 // Set namespace in case obsolete env vars were used to specify a custom namespace for the configmap
62 migratedConfig.Namespace = namespace
63 if err := client.Create(context.Background(), migratedConfig); err != nil {
64 return err
65 }
66 log.Info("Migrated operator configuration from configmap")
67 return deleteMigratedConfigmap(client)
68}
69
70func deleteMigratedConfigmap(client crclient.Client) error {
71 obsoleteConfigmap := &corev1.ConfigMap{

Calls 4

GetNamespaceFunction · 0.92
getClusterConfigFunction · 0.85
deleteMigratedConfigmapFunction · 0.85