package utils import ( "errors" "fmt" "regexp" "strings" "slices" "edge-infra.dev/pkg/edge/api/graph/model" "edge-infra.dev/pkg/edge/constants" ) var () func GetDockerValsOrFail(values []*model.KeyValues) (string, string, string, error) { var url, username, password string for _, keyVal := range values { if keyVal.Key == "docker-server" { url = keyVal.Value } if keyVal.Key == "docker-username" { username = keyVal.Value } if keyVal.Key == "docker-password" { password = keyVal.Value } } if url == "" || username == "" || password == "" { return "", "", "", errors.New("need to provide docker-server, docker-username, and docker-password") } return url, username, password, nil } func CheckNetworkServicesUpdatePermitted(clusterActive bool, networkServicesInfo []*model.UpdateNetworkServiceInfo, networkServiceByID map[string]string) error { for _, service := range networkServicesInfo { serviceName := networkServiceByID[service.NetworkServiceID] if slices.Contains(constants.FixedClusterServices, serviceName) && clusterActive { return fmt.Errorf("cluster network service %s cannot be updated after bootstrapping the first node", networkServiceByID[service.NetworkServiceID]) } if serviceName == constants.ServiceTypeClusterDNS { return fmt.Errorf("cluster network service %s is not configurable", constants.ServiceTypeClusterDNS) } } return nil } func ClusterLabelsTypeMap(clusterLabels []*model.Label) map[string]bool { labels := make(map[string]bool, 0) for _, clusterLabel := range clusterLabels { if clusterLabel.Type == "edge-type" { labels[clusterLabel.Key] = true } } return labels } /* This function serves to aid compatibility checks, as edge infra version is currently only sent to the Edge DB's available_artifact_versions table in its full patch version. Since we only compare minor versions and the compatibility is inserted based on whats currently in that table, instead of inserting a compatibility for each individual patch version, we insert only the base minor version compatibility with compatible artifacts. */ // TODO (ja185293) Currently base version is needed for versions pre 0.19 due to patch compatibility not being accounted for, remove once 0.18 goes out of support func SetVersionToBaseAndMinorVersion(toBaseVersion, toMinorVersion *string) (string, string) { var base, minor string //set base version, i.e. 1.8.4 -> 1.8.0 if toBaseVersion != nil { parts := strings.Split(*toBaseVersion, ".") if parts[0] == "0" && parts[1] < "19" { re := regexp.MustCompile(`(\d+\.\d+)\.\d+`) base = re.ReplaceAllString(*toBaseVersion, "${1}.0") } else { base = *toBaseVersion } } // set minor version, i.e. 1.8.4 -> 1.8 if toMinorVersion != nil { minorParts := strings.Split(*toMinorVersion, ".") minor = minorParts[0] + "." + minorParts[1] } return base, minor }