mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
feat(ingress): ingresses datatable with add/edit ingresses EE-2615 (#7672)
This commit is contained in:
parent
393d1fc91d
commit
ef1d648c07
68 changed files with 4938 additions and 61 deletions
64
api/kubernetes/cli/configmaps_and_secrets.go
Normal file
64
api/kubernetes/cli/configmaps_and_secrets.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/portainer/portainer/api/database/models"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// GetConfigMapsAndSecrets gets all the ConfigMaps AND all the Secrets for a
|
||||
// given namespace in a k8s endpoint. The result is a list of both config maps
|
||||
// and secrets. The IsSecret boolean property indicates if a given struct is a
|
||||
// secret or configmap.
|
||||
func (kcl *KubeClient) GetConfigMapsAndSecrets(namespace string) ([]models.K8sConfigMapOrSecret, error) {
|
||||
mapsClient := kcl.cli.CoreV1().ConfigMaps(namespace)
|
||||
mapsList, err := mapsClient.List(context.Background(), v1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: Applications
|
||||
var combined []models.K8sConfigMapOrSecret
|
||||
for _, m := range mapsList.Items {
|
||||
var cm models.K8sConfigMapOrSecret
|
||||
cm.UID = string(m.UID)
|
||||
cm.Name = m.Name
|
||||
cm.Namespace = m.Namespace
|
||||
cm.Annotations = m.Annotations
|
||||
cm.Data = m.Data
|
||||
cm.CreationDate = m.CreationTimestamp.Time.UTC().Format(time.RFC3339)
|
||||
cm.IsSecret = false
|
||||
combined = append(combined, cm)
|
||||
}
|
||||
|
||||
secretClient := kcl.cli.CoreV1().Secrets(namespace)
|
||||
secretList, err := secretClient.List(context.Background(), v1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, s := range secretList.Items {
|
||||
var secret models.K8sConfigMapOrSecret
|
||||
secret.UID = string(s.UID)
|
||||
secret.Name = s.Name
|
||||
secret.Namespace = s.Namespace
|
||||
secret.Annotations = s.Annotations
|
||||
secret.Data = msbToMss(s.Data)
|
||||
secret.CreationDate = s.CreationTimestamp.Time.UTC().Format(time.RFC3339)
|
||||
secret.IsSecret = true
|
||||
secret.SecretType = string(s.Type)
|
||||
combined = append(combined, secret)
|
||||
}
|
||||
|
||||
return combined, nil
|
||||
}
|
||||
|
||||
func msbToMss(msa map[string][]byte) map[string]string {
|
||||
mss := make(map[string]string, len(msa))
|
||||
for k, v := range msa {
|
||||
mss[k] = string(v)
|
||||
}
|
||||
return mss
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue