-
Notifications
You must be signed in to change notification settings - Fork 18
/
service.go
42 lines (37 loc) · 959 Bytes
/
service.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
/*
Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
*/
package k8s
import (
"context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func NewKubernetesService(name string, namespace string) *corev1.Service {
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{
"app": name,
},
Ports: []corev1.ServicePort{
{
Port: 9080,
},
},
},
}
}
func CreateKubernetesService(ctx context.Context, client client.Client, key types.NamespacedName, service *corev1.Service) error {
err := client.Get(ctx, key, service)
if err != nil {
err = client.Create(ctx, service)
}
return err
}