diff --git a/devspace.yaml b/devspace.yaml index ac7ecd7..2ba3e0d 100644 --- a/devspace.yaml +++ b/devspace.yaml @@ -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: {} @@ -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 diff --git a/manifests/controller.yaml b/manifests/controller.yaml index 9c7a79b..fc647d3 100644 --- a/manifests/controller.yaml +++ b/manifests/controller.yaml @@ -16,6 +16,10 @@ spec: resource: daemonsets updateStrategy: method: Recreate + - apiVersion: v1 + resource: services + updateStrategy: + method: Recreate hooks: sync: webhook: diff --git a/pkg/generate/generate.go b/pkg/generate/generate.go index 6c435b2..858fe97 100644 --- a/pkg/generate/generate.go +++ b/pkg/generate/generate.go @@ -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" @@ -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", @@ -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",