...

Source file src/edge-infra.dev/pkg/edge/api/utils/resolver_helpers.go

Documentation: edge-infra.dev/pkg/edge/api/utils

     1  package utils
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"regexp"
     7  	"strings"
     8  
     9  	"slices"
    10  
    11  	"edge-infra.dev/pkg/edge/api/graph/model"
    12  	"edge-infra.dev/pkg/edge/constants"
    13  )
    14  
    15  var ()
    16  
    17  func GetDockerValsOrFail(values []*model.KeyValues) (string, string, string, error) {
    18  	var url, username, password string
    19  	for _, keyVal := range values {
    20  		if keyVal.Key == "docker-server" {
    21  			url = keyVal.Value
    22  		}
    23  		if keyVal.Key == "docker-username" {
    24  			username = keyVal.Value
    25  		}
    26  		if keyVal.Key == "docker-password" {
    27  			password = keyVal.Value
    28  		}
    29  	}
    30  	if url == "" || username == "" || password == "" {
    31  		return "", "", "", errors.New("need to provide docker-server, docker-username, and docker-password")
    32  	}
    33  	return url, username, password, nil
    34  }
    35  
    36  func CheckNetworkServicesUpdatePermitted(clusterActive bool, networkServicesInfo []*model.UpdateNetworkServiceInfo, networkServiceByID map[string]string) error {
    37  	for _, service := range networkServicesInfo {
    38  		serviceName := networkServiceByID[service.NetworkServiceID]
    39  		if slices.Contains(constants.FixedClusterServices, serviceName) && clusterActive {
    40  			return fmt.Errorf("cluster network service %s cannot be updated after bootstrapping the first node", networkServiceByID[service.NetworkServiceID])
    41  		}
    42  		if serviceName == constants.ServiceTypeClusterDNS {
    43  			return fmt.Errorf("cluster network service %s is not configurable", constants.ServiceTypeClusterDNS)
    44  		}
    45  	}
    46  	return nil
    47  }
    48  
    49  func ClusterLabelsTypeMap(clusterLabels []*model.Label) map[string]bool {
    50  	labels := make(map[string]bool, 0)
    51  	for _, clusterLabel := range clusterLabels {
    52  		if clusterLabel.Type == "edge-type" {
    53  			labels[clusterLabel.Key] = true
    54  		}
    55  	}
    56  	return labels
    57  }
    58  
    59  /*
    60  	  This function serves to aid compatibility checks, as edge infra version is currently only
    61  		sent to the Edge DB's available_artifact_versions table in its full patch version. Since we only compare
    62  		minor versions and the compatibility is inserted based on whats currently in that table, instead of inserting a compatibility
    63  		for each individual patch version, we insert only the base minor version compatibility with compatible artifacts.
    64  */
    65  
    66  // 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
    67  func SetVersionToBaseAndMinorVersion(toBaseVersion, toMinorVersion *string) (string, string) {
    68  	var base, minor string
    69  	//set base version, i.e. 1.8.4 -> 1.8.0
    70  	if toBaseVersion != nil {
    71  		parts := strings.Split(*toBaseVersion, ".")
    72  		if parts[0] == "0" && parts[1] < "19" {
    73  			re := regexp.MustCompile(`(\d+\.\d+)\.\d+`)
    74  			base = re.ReplaceAllString(*toBaseVersion, "${1}.0")
    75  		} else {
    76  			base = *toBaseVersion
    77  		}
    78  	}
    79  
    80  	// set minor version, i.e. 1.8.4 -> 1.8
    81  	if toMinorVersion != nil {
    82  		minorParts := strings.Split(*toMinorVersion, ".")
    83  		minor = minorParts[0] + "." + minorParts[1]
    84  	}
    85  	return base, minor
    86  }
    87  

View as plain text