github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/api/migrate/grafana/v1beta1tov1beta2.go (about) 1 package grafana 2 3 import ( 4 "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring" 5 "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/admin" 6 "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth" 7 generic "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Generic" 8 github "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Github" 9 gitlab "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Gitlab" 10 google "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Google" 11 "github.com/caos/orbos/internal/operator/boom/api/migrate/network" 12 "github.com/caos/orbos/internal/operator/boom/api/migrate/storage" 13 "github.com/caos/orbos/internal/operator/boom/api/v1beta1/grafana" 14 "github.com/caos/orbos/pkg/secret" 15 ) 16 17 func V1beta1Tov1beta2(grafana *grafana.Grafana) *monitoring.Monitoring { 18 newSpec := &monitoring.Monitoring{ 19 Deploy: grafana.Deploy, 20 NodeSelector: grafana.NodeSelector, 21 } 22 if grafana.Datasources != nil && len(grafana.Datasources) > 0 { 23 datasources := make([]*monitoring.Datasource, 0) 24 for _, v := range grafana.Datasources { 25 newSpec.Datasources = append(newSpec.Datasources, &monitoring.Datasource{ 26 Name: v.Name, 27 Type: v.Type, 28 Url: v.Url, 29 Access: v.Access, 30 IsDefault: v.IsDefault, 31 }) 32 } 33 newSpec.Datasources = datasources 34 } 35 36 if grafana.DashboardProviders != nil && len(grafana.DashboardProviders) > 0 { 37 providers := make([]*monitoring.Provider, 0) 38 for _, v := range grafana.DashboardProviders { 39 provider := &monitoring.Provider{ 40 ConfigMaps: nil, 41 Folder: v.Folder, 42 } 43 if v.ConfigMaps != nil && len(v.ConfigMaps) > 0 { 44 for _, v := range v.ConfigMaps { 45 provider.ConfigMaps = append(provider.ConfigMaps, v) 46 } 47 } 48 newSpec.DashboardProviders = append(newSpec.DashboardProviders, provider) 49 } 50 newSpec.DashboardProviders = providers 51 } 52 53 if grafana.Admin != nil { 54 newSpec.Admin = &admin.Admin{ 55 Username: grafana.Admin.Username, 56 Password: grafana.Admin.Password, 57 ExistingUsername: &secret.Existing{ 58 Name: grafana.Admin.ExistingSecret.Name, 59 Key: grafana.Admin.ExistingSecret.IDKey, 60 }, 61 ExistingPassword: &secret.Existing{ 62 Name: grafana.Admin.ExistingSecret.Name, 63 Key: grafana.Admin.ExistingSecret.SecretKey, 64 }, 65 } 66 } 67 68 if grafana.Network != nil { 69 newSpec.Network = network.V1beta1Tov1beta2(grafana.Network) 70 } 71 72 if grafana.Storage != nil { 73 newSpec.Storage = storage.V1beta1Tov1beta2(grafana.Storage) 74 } 75 76 if grafana.Auth != nil { 77 oldAuth := grafana.Auth 78 newAuth := auth.Auth{} 79 if oldAuth.Google != nil { 80 newAuth.Google = &google.Auth{ 81 ClientID: oldAuth.Google.ClientID, 82 ExistingClientIDSecret: oldAuth.Google.ExistingClientIDSecret, 83 ClientSecret: oldAuth.Google.ClientSecret, 84 ExistingClientSecretSecret: oldAuth.Google.ExistingClientSecretSecret, 85 } 86 if oldAuth.Google.AllowedDomains != nil { 87 domains := make([]string, 0) 88 for _, v := range oldAuth.Google.AllowedDomains { 89 domains = append(domains, v) 90 } 91 newAuth.Google.AllowedDomains = domains 92 } 93 } 94 if oldAuth.Github != nil { 95 newAuth.Github = &github.Auth{ 96 ClientID: oldAuth.Github.ClientID, 97 ExistingClientIDSecret: oldAuth.Github.ExistingClientIDSecret, 98 ClientSecret: oldAuth.Github.ClientSecret, 99 ExistingClientSecretSecret: oldAuth.Github.ExistingClientSecretSecret, 100 } 101 if oldAuth.Github.AllowedOrganizations != nil { 102 orgs := make([]string, 0) 103 for _, v := range oldAuth.Github.AllowedOrganizations { 104 orgs = append(orgs, v) 105 } 106 newAuth.Github.AllowedOrganizations = orgs 107 } 108 if oldAuth.Github.TeamIDs != nil { 109 teams := make([]string, 0) 110 for _, v := range oldAuth.Github.TeamIDs { 111 teams = append(teams, v) 112 } 113 newAuth.Github.TeamIDs = teams 114 } 115 } 116 117 if oldAuth.Gitlab != nil { 118 newAuth.Gitlab = &gitlab.Auth{ 119 ClientID: oldAuth.Gitlab.ClientID, 120 ExistingClientIDSecret: oldAuth.Gitlab.ExistingClientIDSecret, 121 ClientSecret: oldAuth.Gitlab.ClientSecret, 122 ExistingClientSecretSecret: oldAuth.Gitlab.ExistingClientSecretSecret, 123 } 124 if oldAuth.Gitlab.AllowedGroups != nil { 125 groups := make([]string, 0) 126 for _, v := range oldAuth.Gitlab.AllowedGroups { 127 groups = append(groups, v) 128 } 129 newAuth.Gitlab.AllowedGroups = groups 130 } 131 } 132 133 if oldAuth.GenericOAuth != nil { 134 newAuth.GenericOAuth = &generic.Auth{ 135 ClientID: oldAuth.GenericOAuth.ClientID, 136 ExistingClientIDSecret: oldAuth.GenericOAuth.ExistingClientIDSecret, 137 ClientSecret: oldAuth.GenericOAuth.ClientSecret, 138 ExistingClientSecretSecret: oldAuth.GenericOAuth.ExistingClientSecretSecret, 139 AuthURL: oldAuth.GenericOAuth.AuthURL, 140 TokenURL: oldAuth.GenericOAuth.TokenURL, 141 APIURL: oldAuth.GenericOAuth.APIURL, 142 } 143 if oldAuth.GenericOAuth.AllowedDomains != nil { 144 domains := make([]string, 0) 145 for _, v := range oldAuth.GenericOAuth.AllowedDomains { 146 domains = append(domains, v) 147 } 148 newAuth.GenericOAuth.AllowedDomains = domains 149 } 150 if oldAuth.GenericOAuth.Scopes != nil { 151 scopes := make([]string, 0) 152 for _, v := range oldAuth.GenericOAuth.Scopes { 153 scopes = append(scopes, v) 154 } 155 newAuth.GenericOAuth.Scopes = scopes 156 } 157 } 158 newSpec.Auth = &newAuth 159 } 160 161 return newSpec 162 }