Skip to content

Commit

Permalink
Create/update/delete ServiceAccount on MeshGateway reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed Nov 21, 2023
1 parent 6638261 commit f7f5f95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package controllersv2

import (
"context"
"errors"

"github.com/go-logr/logr"
k8serr "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -15,6 +14,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

meshv2beta1 "github.com/hashicorp/consul-k8s/control-plane/api/mesh/v2beta1"
"github.com/hashicorp/consul-k8s/control-plane/gateways"
)

// MeshGatewayController reconciles a MeshGateway object.
Expand Down Expand Up @@ -70,10 +70,14 @@ func (r *MeshGatewayController) SetupWithManager(mgr ctrl.Manager) error {

func (r *MeshGatewayController) onCreateUpdate(ctx context.Context, req ctrl.Request, resource *meshv2beta1.MeshGateway) error {
// TODO NET-6392 NET-6393 NET-6394 NET-6395
return errors.New("onCreateUpdate not implemented")

serviceAccount := gateways.NewMeshGatewayServiceAccount(resource)
return r.Create(ctx, serviceAccount)
}

func (r *MeshGatewayController) onDelete(ctx context.Context, req ctrl.Request, resource *meshv2beta1.MeshGateway) error {
// TODO NET-6392 NET-6393 NET-6394 NET-6395
return errors.New("onDelete not implemented")

serviceAccount := gateways.NewMeshGatewayServiceAccount(resource)
return r.Delete(ctx, serviceAccount)
}
18 changes: 18 additions & 0 deletions control-plane/gateways/serviceaccount.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gateways

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/hashicorp/consul-k8s/control-plane/api/mesh/v2beta1"
)

func NewMeshGatewayServiceAccount(gateway *v2beta1.MeshGateway) *corev1.ServiceAccount {
return &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: gateway.Name,
Namespace: gateway.Namespace,
Labels: meshGatewayLabels(gateway),
},
}
}

0 comments on commit f7f5f95

Please sign in to comment.