Skip to content

Commit

Permalink
[#3530] airy controller component name mapping (#3562)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-sebastian authored Aug 9, 2022
1 parent c9f1288 commit ec8c499
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
10 changes: 1 addition & 9 deletions infrastructure/controller/pkg/endpoints/components_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/airyhq/airy/infrastructure/controller/pkg/cache"
"github.com/airyhq/airy/lib/go/k8s"
Expand Down Expand Up @@ -72,14 +71,7 @@ func (s *ComponentsUpdate) ServeHTTP(w http.ResponseWriter, r *http.Request) {

//NOTE: Prevent the upload of a configmap if the component is not present
func (s *ComponentsUpdate) isComponentInstalled(configName string) bool {
name := getNameFromConfigMapName(configName)
deployedCharts := s.DeployedCharts.GetDeployedCharts()

return deployedCharts[name]
}

func getNameFromConfigMapName(name string) string {
c := strings.Split(name, "-")

return strings.Join(c[1:], "-")
return deployedCharts[configName]
}
21 changes: 3 additions & 18 deletions lib/go/k8s/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package k8s
import (
"context"
"fmt"
"strings"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -79,35 +78,21 @@ func GetComponentsConfigMaps(
namespace string,
clientSet *kubernetes.Clientset,
valueTransformer func(map[string]string) map[string]string,
) (map[string]map[string]interface{}, error) {
) (map[string]interface{}, error) {
configmapList, err := clientSet.CoreV1().ConfigMaps(namespace).List(ctx, v1.ListOptions{LabelSelector: "core.airy.co/component"})
if err != nil {
return nil, fmt.Errorf("Unable to list config maps. Error: %s\n", err)
}

components := make(map[string]map[string]interface{})
components := make(map[string]interface{})
for _, configmap := range configmapList.Items {
label, ok := configmap.Labels["core.airy.co/component"]
if !ok {
continue
}

componentsGroup, componentName := getComponentFromLabel(label)

componentsGroupContent, ok := components[componentsGroup]
if !ok {
componentsGroupContent = make(map[string]interface{})
components[componentsGroup] = componentsGroupContent
}

componentsGroupContent[componentName] = valueTransformer(configmap.Data)
components[label] = valueTransformer(configmap.Data)
}

return components, nil
}

func getComponentFromLabel(l string) (string, string) {
c := strings.Split(l, "-")

return c[0], strings.Join(c[1:], "-")
}

0 comments on commit ec8c499

Please sign in to comment.