Skip to content

Commit

Permalink
feat: added service
Browse files Browse the repository at this point in the history
  • Loading branch information
siredmar committed Mar 27, 2023
1 parent 95843aa commit 5c4f151
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pipelines:
dev:
controller:
imageSelector: ${IMAGE}
imageSelector: ghcr.io/edgefarm/edgenetwork-operator/controller:latest
devImage: ghcr.io/loft-sh/devspace-containers/go:1.20-alpine
namespace: metacontroller
terminal: {}
Expand All @@ -44,8 +44,8 @@ dev:
- path: ./:/app
excludePaths:
- .git
atches:
patches:
- op: remove
path: spec.securityContext
- op: remove
path: spec.template.spec.containers[0].resources
path: spec.containers[0].resources
4 changes: 4 additions & 0 deletions manifests/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ spec:
resource: daemonsets
updateStrategy:
method: Recreate
- apiVersion: v1
resource: services
updateStrategy:
method: Recreate
hooks:
sync:
webhook:
Expand Down
44 changes: 44 additions & 0 deletions pkg/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"

v1alpha1 "github.com/edgefarm/edgenetwork-operator/apis/edgenetwork/v1alpha1"
json "github.com/edgefarm/edgenetwork-operator/pkg/json"
Expand All @@ -26,6 +27,9 @@ func Manifests(config *v1alpha1.EdgeNetwork) ([]runtime.Object, error) {
response = append(response, cm)
name := fmt.Sprintf("%s-%s", config.Spec.Network, config.Spec.SubNetwork)

service := getService(config)
response = append(response, service)

daemonSet := &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Expand Down Expand Up @@ -195,6 +199,46 @@ func getNodeSelectorTerms(config *v1alpha1.EdgeNetwork) []v1.NodeSelectorTerm {
return ret
}

func getService(config *v1alpha1.EdgeNetwork) *v1.Service {
name := fmt.Sprintf("%s-%s", config.Spec.Network, config.Spec.SubNetwork)
return &v1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Service",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
"network.edgefarm.io/type": "leaf",
fmt.Sprintf("name.network.edgefarm.io/%s", config.Spec.Network): "",
fmt.Sprintf("subnetwork.network.edgefarm.io/%s", config.Spec.SubNetwork): "",
},
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromInt(4222),
Protocol: v1.ProtocolTCP,
},
{
Name: "nats-metrics",
Port: 8222,
TargetPort: intstr.FromInt(8222),
Protocol: v1.ProtocolTCP,
},
},
Selector: map[string]string{
"network.edgefarm.io/type": "leaf",
fmt.Sprintf("name.network.edgefarm.io/%s", config.Spec.Network): "",
fmt.Sprintf("subnetwork.network.edgefarm.io/%s", config.Spec.SubNetwork): "",
},
Type: v1.ServiceTypeClusterIP,
},
}
}

func getNatsInitContainer(config *v1alpha1.EdgeNetwork) v1.Container {
return v1.Container{
Name: "init",
Expand Down

0 comments on commit 5c4f151

Please sign in to comment.