Skip to content

Commit

Permalink
Force all GTP events to update only (#235)
Browse files Browse the repository at this point in the history
* Fixes: #234

force GTPs to update only

Signed-off-by: Shriram Sharma <[email protected]>

* fixed linting errors

Signed-off-by: Shriram Sharma <[email protected]>
  • Loading branch information
shriramsharma authored Jun 24, 2022
1 parent d8b06cb commit 3cd7ac8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 8 additions & 5 deletions admiral/pkg/clusters/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,23 @@ func (dh *DependencyHandler) Deleted(obj *v1.Dependency) {

func (gtp *GlobalTrafficHandler) Added(obj *v1.GlobalTrafficPolicy) {
log.Infof(LogFormat, "Added", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
err := HandleEventForGlobalTrafficPolicy(admiral.Add, obj, gtp.RemoteRegistry, gtp.ClusterID)
err := HandleEventForGlobalTrafficPolicy(obj, gtp.RemoteRegistry, gtp.ClusterID)
if err != nil {
log.Infof(err.Error())
}
}

func (gtp *GlobalTrafficHandler) Updated(obj *v1.GlobalTrafficPolicy) {
log.Infof(LogFormat, "Updated", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
err := HandleEventForGlobalTrafficPolicy(admiral.Update, obj, gtp.RemoteRegistry, gtp.ClusterID)
err := HandleEventForGlobalTrafficPolicy(obj, gtp.RemoteRegistry, gtp.ClusterID)
if err != nil {
log.Infof(err.Error())
}
}

func (gtp *GlobalTrafficHandler) Deleted(obj *v1.GlobalTrafficPolicy) {
log.Infof(LogFormat, "Deleted", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
err := HandleEventForGlobalTrafficPolicy(admiral.Delete, obj, gtp.RemoteRegistry, gtp.ClusterID)
err := HandleEventForGlobalTrafficPolicy(obj, gtp.RemoteRegistry, gtp.ClusterID)
if err != nil {
log.Infof(err.Error())
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func HandleEventForDeployment(event admiral.EventType, obj *k8sAppsV1.Deployment
}

// HandleEventForGlobalTrafficPolicy processes all the events related to GTPs
func HandleEventForGlobalTrafficPolicy(event admiral.EventType, gtp *v1.GlobalTrafficPolicy, remoteRegistry *RemoteRegistry, clusterName string) error {
func HandleEventForGlobalTrafficPolicy(gtp *v1.GlobalTrafficPolicy, remoteRegistry *RemoteRegistry, clusterName string) error {

globalIdentifier := common.GetGtpIdentity(gtp)

Expand All @@ -269,7 +269,10 @@ func HandleEventForGlobalTrafficPolicy(event admiral.EventType, gtp *v1.GlobalTr

env := common.GetGtpEnv(gtp)

// For now we're going to force all the events to update only in order to prevent
// the endpoints from being deleted.
// TODO: Need to come up with a way to prevent deleting default endpoints so that this hack can be removed.
// Use the same function as added deployment function to update and put new service entry in place to replace old one
modifyServiceEntryForNewServiceOrPod(event, env, globalIdentifier, remoteRegistry)
modifyServiceEntryForNewServiceOrPod(admiral.Update, env, globalIdentifier, remoteRegistry)
return nil
}
3 changes: 1 addition & 2 deletions admiral/pkg/clusters/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func TestRolloutHandler(t *testing.T) {
}

func TestHandleEventForGlobalTrafficPolicy(t *testing.T) {
event := admiral.EventType("Add")
p := common.AdmiralParams{
KubeconfigPath: "testdata/fake.config",
}
Expand Down Expand Up @@ -253,7 +252,7 @@ func TestHandleEventForGlobalTrafficPolicy(t *testing.T) {

for _, c := range testcases {
t.Run(c.name, func(t *testing.T) {
err := HandleEventForGlobalTrafficPolicy(event, c.gtp, registry, "testcluster")
err := HandleEventForGlobalTrafficPolicy(c.gtp, registry, "testcluster")
assert.Equal(t, err != nil, c.doesError)
})
}
Expand Down

0 comments on commit 3cd7ac8

Please sign in to comment.