Skip to content

Commit

Permalink
Use component names from admiral
Browse files Browse the repository at this point in the history
Use admiral/pkg/names/names.go for component names for consistency
across all repos/components.

Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar committed Aug 7, 2023
1 parent b78368b commit e58b2c1
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 103 deletions.
9 changes: 5 additions & 4 deletions controllers/servicediscovery/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (

"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/finalizer"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/resource"
"github.com/submariner-io/admiral/pkg/util"
operatorv1alpha1 "github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/uninstall"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -39,7 +40,7 @@ import (
)

func (r *Reconciler) doCleanup(ctx context.Context, instance *operatorv1alpha1.ServiceDiscovery) (reconcile.Result, error) {
if !finalizer.IsPresent(instance, names.CleanupFinalizer) {
if !finalizer.IsPresent(instance, opnames.CleanupFinalizer) {
return reconcile.Result{}, nil
}

Expand Down Expand Up @@ -73,7 +74,7 @@ func (r *Reconciler) doCleanup(ctx context.Context, instance *operatorv1alpha1.S
Namespace: instance.Namespace,
},
},
UninstallResource: newLighthouseAgent(instance, names.AppendUninstall(names.ServiceDiscoveryComponent)),
UninstallResource: newLighthouseAgent(instance, opnames.AppendUninstall(names.ServiceDiscoveryComponent)),
},
}

Expand Down Expand Up @@ -103,7 +104,7 @@ func (r *Reconciler) doCleanup(ctx context.Context, instance *operatorv1alpha1.S
//nolint:wrapcheck // No need to wrap
func (r *Reconciler) removeFinalizer(ctx context.Context, instance *operatorv1alpha1.ServiceDiscovery) error {
return finalizer.Remove(ctx, resource.ForControllerClient(r.ScopedClient, instance.Namespace, instance),
instance, names.CleanupFinalizer)
instance, opnames.CleanupFinalizer)
}

func (r *Reconciler) removeLighthouseConfigFromCustomDNSConfigMap(ctx context.Context,
Expand Down
9 changes: 5 additions & 4 deletions controllers/servicediscovery/servicediscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import (
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/finalizer"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/resource"
"github.com/submariner-io/admiral/pkg/syncer/broker"
"github.com/submariner-io/admiral/pkg/util"
submarinerv1alpha1 "github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/controllers/metrics"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -181,7 +182,7 @@ func (r *Reconciler) addFinalizer(ctx context.Context,
instance *submarinerv1alpha1.ServiceDiscovery,
) (*submarinerv1alpha1.ServiceDiscovery, error) {
added, err := finalizer.Add(ctx, resource.ForControllerClient(r.ScopedClient, instance.Namespace,
&submarinerv1alpha1.ServiceDiscovery{}), instance, names.CleanupFinalizer)
&submarinerv1alpha1.ServiceDiscovery{}), instance, opnames.CleanupFinalizer)
if err != nil {
return nil, err //nolint:wrapcheck // No need to wrap
}
Expand Down Expand Up @@ -238,7 +239,7 @@ func newLighthouseAgent(cr *submarinerv1alpha1.ServiceDiscovery, name string) *a
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, names.ServiceDiscoveryImage, names.ServiceDiscoveryComponent),
Image: getImagePath(cr, opnames.ServiceDiscoveryImage, names.ServiceDiscoveryComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.ServiceDiscoveryComponent]),
Env: []corev1.EnvVar{
{Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace},
Expand Down Expand Up @@ -334,7 +335,7 @@ func newLighthouseCoreDNSDeployment(cr *submarinerv1alpha1.ServiceDiscovery) *ap
Containers: []corev1.Container{
{
Name: names.LighthouseCoreDNSComponent,
Image: getImagePath(cr, names.LighthouseCoreDNSImage, names.LighthouseCoreDNSComponent),
Image: getImagePath(cr, opnames.LighthouseCoreDNSImage, names.LighthouseCoreDNSComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.LighthouseCoreDNSComponent]),
Env: []corev1.EnvVar{
{Name: "SUBMARINER_CLUSTERID", Value: cr.Spec.ClusterID},
Expand Down
15 changes: 8 additions & 7 deletions controllers/servicediscovery/servicediscovery_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/submariner-io/admiral/pkg/names"
submariner_v1 "github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -200,14 +201,14 @@ func testCoreDNSCleanup() {
t := newTestDriver()

BeforeEach(func() {
t.serviceDiscovery.SetFinalizers([]string{names.CleanupFinalizer})
t.serviceDiscovery.SetFinalizers([]string{opnames.CleanupFinalizer})

now := metav1.Now()
t.serviceDiscovery.SetDeletionTimestamp(&now)
})

JustBeforeEach(func() {
deployment := t.NewDeployment(names.AppendUninstall(names.ServiceDiscoveryComponent))
deployment := t.NewDeployment(opnames.AppendUninstall(names.ServiceDiscoveryComponent))

var one int32 = 1
deployment.Spec.Replicas = &one
Expand Down Expand Up @@ -281,7 +282,7 @@ func testDeploymentUninstall() {
t := newTestDriver()

BeforeEach(func() {
t.serviceDiscovery.SetFinalizers([]string{names.CleanupFinalizer})
t.serviceDiscovery.SetFinalizers([]string{opnames.CleanupFinalizer})

now := metav1.Now()
t.serviceDiscovery.SetDeletionTimestamp(&now)
Expand All @@ -304,12 +305,12 @@ func testDeploymentUninstall() {

t.AssertReconcileSuccess()

t.AssertNoDeployment(names.AppendUninstall(names.ServiceDiscoveryComponent))
t.AssertNoDeployment(opnames.AppendUninstall(names.ServiceDiscoveryComponent))

t.awaitServiceDiscoveryDeleted()

t.AssertReconcileSuccess()
t.AssertNoDeployment(names.AppendUninstall(names.ServiceDiscoveryComponent))
t.AssertNoDeployment(opnames.AppendUninstall(names.ServiceDiscoveryComponent))
})
})

Expand All @@ -326,7 +327,7 @@ func testDeploymentUninstall() {
_, err := t.GetDeployment(names.ServiceDiscoveryComponent)
Expect(err).To(Succeed())

t.AssertNoDeployment(names.AppendUninstall(names.ServiceDiscoveryComponent))
t.AssertNoDeployment(opnames.AppendUninstall(names.ServiceDiscoveryComponent))

t.awaitServiceDiscoveryDeleted()
})
Expand Down
9 changes: 5 additions & 4 deletions controllers/servicediscovery/servicediscovery_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
. "github.com/onsi/gomega"
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/submariner-io/admiral/pkg/log/kzerolog"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/servicediscovery"
"github.com/submariner-io/submariner-operator/controllers/test"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -104,18 +105,18 @@ func newTestDriver() *testDriver {
}

func (t *testDriver) awaitFinalizer() {
t.AwaitFinalizer(t.serviceDiscovery, names.CleanupFinalizer)
t.AwaitFinalizer(t.serviceDiscovery, opnames.CleanupFinalizer)
}

func (t *testDriver) awaitServiceDiscoveryDeleted() {
t.AwaitNoResource(t.serviceDiscovery)
}

func (t *testDriver) assertUninstallServiceDiscoveryDeployment() *appsv1.Deployment {
deployment := t.AssertDeployment(names.AppendUninstall(names.ServiceDiscoveryComponent))
deployment := t.AssertDeployment(opnames.AppendUninstall(names.ServiceDiscoveryComponent))

t.AssertUninstallInitContainer(&deployment.Spec.Template,
fmt.Sprintf("%s/%s:%s", t.serviceDiscovery.Spec.Repository, names.ServiceDiscoveryImage, t.serviceDiscovery.Spec.Version))
fmt.Sprintf("%s/%s:%s", t.serviceDiscovery.Spec.Repository, opnames.ServiceDiscoveryImage, t.serviceDiscovery.Spec.Version))

return deployment
}
Expand Down
15 changes: 8 additions & 7 deletions controllers/submariner/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"time"

"github.com/submariner-io/admiral/pkg/finalizer"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/resource"
operatorv1alpha1 "github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/uninstall"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -36,7 +37,7 @@ import (
)

func (r *Reconciler) runComponentCleanup(ctx context.Context, instance *operatorv1alpha1.Submariner) (reconcile.Result, error) {
if !finalizer.IsPresent(instance, names.CleanupFinalizer) {
if !finalizer.IsPresent(instance, opnames.CleanupFinalizer) {
return reconcile.Result{}, nil
}

Expand All @@ -54,23 +55,23 @@ func (r *Reconciler) runComponentCleanup(ctx context.Context, instance *operator
components := []*uninstall.Component{
{
Resource: newDaemonSet(names.GatewayComponent, instance.Namespace),
UninstallResource: newGatewayDaemonSet(instance, names.AppendUninstall(names.GatewayComponent)),
UninstallResource: newGatewayDaemonSet(instance, opnames.AppendUninstall(names.GatewayComponent)),
},
{
Resource: newDaemonSet(names.RouteAgentComponent, instance.Namespace),
UninstallResource: newRouteAgentDaemonSet(instance, clusterNetwork, names.AppendUninstall(names.RouteAgentComponent)),
UninstallResource: newRouteAgentDaemonSet(instance, clusterNetwork, opnames.AppendUninstall(names.RouteAgentComponent)),
},
{
Resource: newDaemonSet(names.GlobalnetComponent, instance.Namespace),
UninstallResource: newGlobalnetDaemonSet(instance, names.AppendUninstall(names.GlobalnetComponent)),
UninstallResource: newGlobalnetDaemonSet(instance, opnames.AppendUninstall(names.GlobalnetComponent)),
CheckInstalled: func() bool {
return instance.Spec.GlobalCIDR != ""
},
},
{
Resource: newDeployment(names.NetworkPluginSyncerComponent, instance.Namespace),
UninstallResource: newNetworkPluginSyncerDeployment(instance, clusterNetwork,
names.AppendUninstall(names.NetworkPluginSyncerComponent)),
opnames.AppendUninstall(names.NetworkPluginSyncerComponent)),
CheckInstalled: func() bool {
return needsNetworkPluginSyncer(instance)
},
Expand Down Expand Up @@ -107,7 +108,7 @@ func (r *Reconciler) runComponentCleanup(ctx context.Context, instance *operator
//nolint:wrapcheck // No need to wrap
func (r *Reconciler) removeFinalizer(ctx context.Context, instance *operatorv1alpha1.Submariner) error {
return finalizer.Remove(ctx, resource.ForControllerClient(r.config.ScopedClient, instance.Namespace, &operatorv1alpha1.Submariner{}),
instance, names.CleanupFinalizer)
instance, opnames.CleanupFinalizer)
}

func (r *Reconciler) ensureServiceDiscoveryDeleted(ctx context.Context, namespace string) bool {
Expand Down
5 changes: 3 additions & 2 deletions controllers/submariner/gateway_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/syncer/broker"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/controllers/metrics"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/port"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -148,7 +149,7 @@ func newGatewayPodTemplate(cr *v1alpha1.Submariner, name string, podSelectorLabe
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, names.GatewayImage, names.GatewayComponent),
Image: getImagePath(cr, opnames.GatewayImage, names.GatewayComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.GatewayComponent]),
Command: []string{"submariner.sh"},
SecurityContext: &corev1.SecurityContext{
Expand Down
5 changes: 3 additions & 2 deletions controllers/submariner/globalnet_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
"context"

"github.com/go-logr/logr"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/controllers/metrics"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -77,7 +78,7 @@ func newGlobalnetDaemonSet(cr *v1alpha1.Submariner, name string) *appsv1.DaemonS
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, names.GlobalnetImage, names.GlobalnetComponent),
Image: getImagePath(cr, opnames.GlobalnetImage, names.GlobalnetComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.GlobalnetComponent]),
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{Add: []corev1.Capability{"ALL"}},
Expand Down
2 changes: 1 addition & 1 deletion controllers/submariner/loadbalancer_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"github.com/go-logr/logr"
configv1 "github.com/openshift/api/config/v1"
"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/resource"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/pkg/names"
submv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/port"
corev1 "k8s.io/api/core/v1"
Expand Down
5 changes: 3 additions & 2 deletions controllers/submariner/metrics_proxy_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"fmt"

"github.com/go-logr/logr"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -82,7 +83,7 @@ func newMetricsProxyDaemonSet(cr *v1alpha1.Submariner) *appsv1.DaemonSet {
func metricProxyContainer(cr *v1alpha1.Submariner, name, hostPort, podPort string) *corev1.Container {
return &corev1.Container{
Name: name,
Image: getImagePath(cr, names.MetricsProxyImage, names.MetricsProxyComponent),
Image: getImagePath(cr, opnames.MetricsProxyImage, names.MetricsProxyComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.MetricsProxyComponent]),
Env: []corev1.EnvVar{
{Name: "NODE_IP", ValueFrom: &corev1.EnvVarSource{
Expand Down
5 changes: 3 additions & 2 deletions controllers/submariner/np_syncer_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"strconv"

"github.com/go-logr/logr"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/pkg/discovery/network"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
"github.com/submariner-io/submariner/pkg/cni"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -84,7 +85,7 @@ func newNetworkPluginSyncerDeployment(cr *v1alpha1.Submariner, clusterNetwork *n
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, names.NetworkPluginSyncerImage, names.NetworkPluginSyncerComponent),
Image: getImagePath(cr, opnames.NetworkPluginSyncerImage, names.NetworkPluginSyncerComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.NetworkPluginSyncerComponent]),
Command: []string{"submariner-networkplugin-syncer.sh"},
Env: []corev1.EnvVar{
Expand Down
5 changes: 3 additions & 2 deletions controllers/submariner/route_agent_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"strconv"

"github.com/go-logr/logr"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/apply"
"github.com/submariner-io/submariner-operator/pkg/discovery/network"
"github.com/submariner-io/submariner-operator/pkg/images"
"github.com/submariner-io/submariner-operator/pkg/names"
opnames "github.com/submariner-io/submariner-operator/pkg/names"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -92,7 +93,7 @@ func newRouteAgentDaemonSet(cr *v1alpha1.Submariner, clusterNetwork *network.Clu
Containers: []corev1.Container{
{
Name: name,
Image: getImagePath(cr, names.RouteAgentImage, names.RouteAgentComponent),
Image: getImagePath(cr, opnames.RouteAgentImage, names.RouteAgentComponent),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version, cr.Spec.ImageOverrides[names.RouteAgentComponent]),
// FIXME: Should be entrypoint script, find/use correct file for routeagent
Command: []string{"submariner-route-agent.sh"},
Expand Down
Loading

0 comments on commit e58b2c1

Please sign in to comment.