-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathfactory.go
65 lines (50 loc) · 1.65 KB
/
factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// License: OpenFaaS Community Edition (CE) EULA
// Copyright (c) 2017,2019-2024 OpenFaaS Author(s)
package k8s
import (
"context"
vv1 "github.com/openfaas/faas-netes/pkg/apis/openfaas/v1"
openfaasv1 "github.com/openfaas/faas-netes/pkg/client/clientset/versioned/typed/openfaas/v1"
v1 "github.com/openfaas/faas-netes/pkg/client/listers/openfaas/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
)
// FunctionFactory is handling Kubernetes operations to materialise functions into deployments and services
type FunctionFactory struct {
Client kubernetes.Interface
Config DeploymentConfig
}
func NewFunctionFactory(clientset kubernetes.Interface, config DeploymentConfig, faasclient openfaasv1.OpenfaasV1Interface) FunctionFactory {
return FunctionFactory{
Client: clientset,
Config: config,
}
}
type Lister struct {
f openfaasv1.OpenfaasV1Interface
}
func (l *Lister) Profiles(namespace string) v1.ProfileNamespaceLister {
return &NamespaceLister{f: l.f, ns: namespace}
}
type NamespaceLister struct {
f openfaasv1.OpenfaasV1Interface
ns string
}
func (l *NamespaceLister) Get(name string) (ret *vv1.Profile, err error) {
value, err := l.f.Profiles(l.ns).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return value, nil
}
func (l *NamespaceLister) List(selector labels.Selector) (ret []*vv1.Profile, err error) {
list, err := l.f.Profiles(l.ns).List(context.Background(), metav1.ListOptions{LabelSelector: selector.String()})
if err != nil {
return nil, err
}
for _, item := range list.Items {
ret = append(ret, &item)
}
return ret, nil
}