Try using a clientset
This commit is contained in:
parent
308367dcdf
commit
32844d3b00
@ -9,8 +9,10 @@ import (
|
||||
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/kube"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
@ -150,23 +152,14 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]string, error) {
|
||||
Insecure: true,
|
||||
},
|
||||
}
|
||||
controller, err := ctrl.NewManager(conf, ctrl.Options{})
|
||||
clientset, err := kubernetes.NewForConfig(conf)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
cms := corev1.ConfigMapList{}
|
||||
cl := controller.GetClient()
|
||||
|
||||
labels := client.MatchingLabels{
|
||||
"kind": "environment",
|
||||
}
|
||||
ns := client.InNamespace(env.UserID)
|
||||
if err := cl.List(ctx, &cms, labels, ns); err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
}
|
||||
secrets, err := clientset.CoreV1().Secrets("").List(context.TODO(), metav1.ListOptions{LabelSelector: "kind=environment" })
|
||||
|
||||
result := []string{}
|
||||
for _, env := range cms.Items {
|
||||
for _, env := range secrets.Items {
|
||||
result = append(result, env.Name)
|
||||
}
|
||||
return result, nil
|
||||
|
Loading…
Reference in New Issue
Block a user