Skip to content

Commit

Permalink
fix: retaining tags on entities while using select-tags (#156)
Browse files Browse the repository at this point in the history
* fix: retaining tags on entities while using select-tags

As of now, while running deck with --select-tags,
the tags are removed from the `tags` field on
each entity. This was done to reduce duplication.
However, this has been confusing for a lot of our
deck users.

This change removes the tag removal function
calls from all entities.

* test: fixed integration tags for tag retention with --select-tags

* fix: lint fix

* fix: fixed integration test for deck dump with --select-tags
  • Loading branch information
Prashansa-K authored Jan 16, 2025
1 parent 3edb1a5 commit 55d27ec
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 31 deletions.
26 changes: 1 addition & 25 deletions pkg/file/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ func getFRouteFromRoute(r *state.Route, kongState *state.KongState, config Write
}
utils.ZeroOutID(r, r.Name, config.WithID)
utils.ZeroOutTimestamps(r)
utils.MustRemoveTags(&r.Route, config.SelectTags)

route := &FRoute{Route: r.Route}

Expand All @@ -316,7 +315,6 @@ func getFRouteFromRoute(r *state.Route, kongState *state.KongState, config Write
p.Route = nil
utils.ZeroOutID(p, p.Name, config.WithID)
utils.ZeroOutTimestamps(p)
utils.MustRemoveTags(&p.Plugin, config.SelectTags)
route.Plugins = append(route.Plugins, &FPlugin{Plugin: p.Plugin})
}
sort.SliceStable(route.Plugins, func(i, j int) bool {
Expand All @@ -327,7 +325,6 @@ func getFRouteFromRoute(r *state.Route, kongState *state.KongState, config Write
f.Route = nil
utils.ZeroOutID(f, f.Name, config.WithID)
utils.ZeroOutTimestamps(f)
utils.MustRemoveTags(&f.FilterChain, config.SelectTags)
route.FilterChains = append(route.FilterChains, &FFilterChain{FilterChain: f.FilterChain})
}
sort.SliceStable(route.FilterChains, func(i, j int) bool {
Expand Down Expand Up @@ -362,7 +359,6 @@ func fetchService(id string, kongState *state.KongState, config WriteConfig) (*F
p.Service = nil
utils.ZeroOutID(p, p.Name, config.WithID)
utils.ZeroOutTimestamps(p)
utils.MustRemoveTags(&p.Plugin, config.SelectTags)
s.Plugins = append(s.Plugins, &FPlugin{Plugin: p.Plugin})
}
sort.SliceStable(s.Plugins, func(i, j int) bool {
Expand All @@ -383,15 +379,13 @@ func fetchService(id string, kongState *state.KongState, config WriteConfig) (*F
f.Service = nil
utils.ZeroOutID(f, f.Name, config.WithID)
utils.ZeroOutTimestamps(f)
utils.MustRemoveTags(&f.FilterChain, config.SelectTags)
s.FilterChains = append(s.FilterChains, &FFilterChain{FilterChain: f.FilterChain})
}
sort.SliceStable(s.FilterChains, func(i, j int) bool {
return compareOrder(s.FilterChains[i], s.FilterChains[j])
})
utils.ZeroOutID(&s, s.Name, config.WithID)
utils.ZeroOutTimestamps(&s)
utils.MustRemoveTags(&s, config.SelectTags)
return &s, nil
}

Expand Down Expand Up @@ -478,7 +472,6 @@ func populatePlugins(kongState *state.KongState, file *Content,
if associations == 0 || associations > 1 {
utils.ZeroOutID(p, p.Name, config.WithID)
utils.ZeroOutTimestamps(p)
utils.MustRemoveTags(&p.Plugin, config.SelectTags)
p := FPlugin{Plugin: p.Plugin}
file.Plugins = append(file.Plugins, p)
}
Expand Down Expand Up @@ -550,15 +543,13 @@ func populateUpstreams(kongState *state.KongState, file *Content,
t.Upstream = nil
utils.ZeroOutID(t, t.Target.Target, config.WithID)
utils.ZeroOutTimestamps(t)
utils.MustRemoveTags(&t.Target, config.SelectTags)
u.Targets = append(u.Targets, &FTarget{Target: t.Target})
}
sort.SliceStable(u.Targets, func(i, j int) bool {
return compareOrder(u.Targets[i], u.Targets[j])
})
utils.ZeroOutID(&u, u.Name, config.WithID)
utils.ZeroOutTimestamps(&u)
utils.MustRemoveTags(&u.Upstream, config.SelectTags)
file.Upstreams = append(file.Upstreams, u)
}
sort.SliceStable(file.Upstreams, func(i, j int) bool {
Expand All @@ -578,7 +569,6 @@ func populateVaults(kongState *state.KongState, file *Content,
v := FVault{Vault: v.Vault}
utils.ZeroOutID(&v, v.Prefix, config.WithID)
utils.ZeroOutTimestamps(&v)
utils.MustRemoveTags(&v.Vault, config.SelectTags)
file.Vaults = append(file.Vaults, v)
}
sort.SliceStable(file.Vaults, func(i, j int) bool {
Expand Down Expand Up @@ -609,14 +599,12 @@ func populateCertificates(kongState *state.KongState, file *Content,
s.Certificate = nil
utils.ZeroOutID(s, s.Name, config.WithID)
utils.ZeroOutTimestamps(s)
utils.MustRemoveTags(&s.SNI, config.SelectTags)
c.SNIs = append(c.SNIs, s.SNI)
}
sort.SliceStable(c.SNIs, func(i, j int) bool {
return strings.Compare(*c.SNIs[i].Name, *c.SNIs[j].Name) < 0
})
utils.ZeroOutTimestamps(&c)
utils.MustRemoveTags(&c, config.SelectTags)
file.Certificates = append(file.Certificates, c)
}
sort.SliceStable(file.Certificates, func(i, j int) bool {
Expand All @@ -626,7 +614,7 @@ func populateCertificates(kongState *state.KongState, file *Content,
}

func populateCACertificates(kongState *state.KongState, file *Content,
config WriteConfig,
_ WriteConfig,
) error {
caCertificates, err := kongState.CACertificates.GetAll()
if err != nil {
Expand All @@ -635,7 +623,6 @@ func populateCACertificates(kongState *state.KongState, file *Content,
for _, c := range caCertificates {
c := FCACertificate{CACertificate: c.CACertificate}
utils.ZeroOutTimestamps(&c)
utils.MustRemoveTags(&c.CACertificate, config.SelectTags)
file.CACertificates = append(file.CACertificates, c)
}
sort.SliceStable(file.CACertificates, func(i, j int) bool {
Expand Down Expand Up @@ -668,7 +655,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
utils.ZeroOutID(p, p.Name, config.WithID)
utils.ZeroOutTimestamps(p)
p.Consumer = nil
utils.MustRemoveTags(&p.Plugin, config.SelectTags)
c.Plugins = append(c.Plugins, &FPlugin{Plugin: p.Plugin})
}
sort.SliceStable(c.Plugins, func(i, j int) bool {
Expand All @@ -682,7 +668,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
for _, k := range keyAuths {
utils.ZeroOutID(k, k.Key, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
k.Consumer = nil
c.KeyAuths = append(c.KeyAuths, &k.KeyAuth)
}
Expand All @@ -694,7 +679,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
k.Consumer = nil
utils.ZeroOutID(k, k.Username, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
c.HMACAuths = append(c.HMACAuths, &k.HMACAuth)
}
jwtSecrets, err := kongState.JWTAuths.GetAllByConsumerID(*c.ID)
Expand All @@ -705,7 +689,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
k.Consumer = nil
utils.ZeroOutID(k, k.Key, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
c.JWTAuths = append(c.JWTAuths, &k.JWTAuth)
}
basicAuths, err := kongState.BasicAuths.GetAllByConsumerID(*c.ID)
Expand All @@ -716,7 +699,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
k.Consumer = nil
utils.ZeroOutID(k, k.Username, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
c.BasicAuths = append(c.BasicAuths, &k.BasicAuth)
}
oauth2Creds, err := kongState.Oauth2Creds.GetAllByConsumerID(*c.ID)
Expand All @@ -727,7 +709,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
k.Consumer = nil
utils.ZeroOutID(k, k.ClientID, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
c.Oauth2Creds = append(c.Oauth2Creds, &k.Oauth2Credential)
}
aclGroups, err := kongState.ACLGroups.GetAllByConsumerID(*c.ID)
Expand All @@ -738,7 +719,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
k.Consumer = nil
utils.ZeroOutID(k, k.Group, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
c.ACLGroups = append(c.ACLGroups, &k.ACLGroup)
}
mtlsAuths, err := kongState.MTLSAuths.GetAllByConsumerID(*c.ID)
Expand All @@ -747,7 +727,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
}
for _, k := range mtlsAuths {
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
k.Consumer = nil
c.MTLSAuths = append(c.MTLSAuths, &k.MTLSAuth)
}
Expand All @@ -763,15 +742,13 @@ func populateConsumers(kongState *state.KongState, file *Content,
}
utils.ZeroOutID(&cg, cg.Name, config.WithID)
utils.ZeroOutTimestamps(&cg)
utils.MustRemoveTags(&cg.ConsumerGroup, config.SelectTags)
c.Groups = append(c.Groups, cg.DeepCopy())
}
sort.SliceStable(c.Plugins, func(i, j int) bool {
return compareOrder(c.Plugins[i], c.Plugins[j])
})
utils.ZeroOutID(&c, c.Username, config.WithID)
utils.ZeroOutTimestamps(&c)
utils.MustRemoveTags(&c.Consumer, config.SelectTags)
file.Consumers = append(file.Consumers, c)
}
rbacRoles, err := kongState.RBACRoles.GetAll()
Expand Down Expand Up @@ -869,7 +846,6 @@ func populateLicenses(kongState *state.KongState, file *Content,
l := FLicense{License: l.License}
utils.ZeroOutID(&l, l.Payload, config.WithID)
utils.ZeroOutTimestamps(&l)
utils.MustRemoveTags(&l.License, config.SelectTags)
file.Licenses = append(file.Licenses, l)
}
sort.SliceStable(file.Licenses, func(i, j int) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,48 @@ certificates:
-----END PRIVATE KEY-----
snis:
- name: demo1.example.com
tags:
- managed-by-deck
- org-unit-42
- name: demo2.example.com
tags:
- managed-by-deck
- org-unit-42
- name: demo3.example.com
tags:
- managed-by-deck
- org-unit-42
tags:
- cloudops-managed
- managed-by-deck
- org-unit-42
consumers:
- acls:
- group: foo-group
tags:
- managed-by-deck
- org-unit-42
hmacauth_credentials:
- secret: yeNZBeqCuk0D3H85VX77Umacf91MwqRo
tags:
- managed-by-deck
- org-unit-42
username: hmac-user
jwt_secrets:
- algorithm: HS256
key: MKWeR0nu9OAUR9HrjpUG82Hbfz7ZXsIw
secret: 6gkrxTKAraykMSpmnLNEGiEE3Yz8XL6U
tags:
- managed-by-deck
- org-unit-42
keyauth_credentials:
- key: iwb6Djkk4HhUlOCmLilDIKh6nZrn90ts
tags:
- managed-by-deck
- org-unit-42
tags:
- managed-by-deck
- org-unit-42
username: harry
plugins:
- config:
Expand All @@ -85,6 +111,9 @@ plugins:
protocols:
- http
- https
tags:
- managed-by-deck
- org-unit-42
services:
- connect_timeout: 60000
enabled: true
Expand All @@ -108,8 +137,13 @@ services:
request_buffering: true
response_buffering: true
strip_path: true
tags:
- managed-by-deck
- org-unit-42
tags:
- team-svc1
- managed-by-deck
- org-unit-42
write_timeout: 60000
- connect_timeout: 60000
enabled: true
Expand All @@ -133,6 +167,12 @@ services:
request_buffering: true
response_buffering: true
strip_path: true
tags:
- managed-by-deck
- org-unit-42
tags:
- managed-by-deck
- org-unit-42
write_timeout: 60000
- connect_timeout: 60000
enabled: true
Expand All @@ -158,6 +198,12 @@ services:
request_buffering: true
response_buffering: true
strip_path: true
tags:
- managed-by-deck
- org-unit-42
tags:
- managed-by-deck
- org-unit-42
write_timeout: 60000
upstreams:
- algorithm: round-robin
Expand Down Expand Up @@ -226,11 +272,23 @@ upstreams:
threshold: 0
name: upstream1
slots: 10000
tags:
- managed-by-deck
- org-unit-42
targets:
- target: 198.51.100.11:80
- tags:
- managed-by-deck
- org-unit-42
target: 198.51.100.11:80
weight: 100
- target: 198.51.100.12:80
- tags:
- managed-by-deck
- org-unit-42
target: 198.51.100.12:80
weight: 100
- target: 198.51.100.13:80
- tags:
- managed-by-deck
- org-unit-42
target: 198.51.100.13:80
weight: 100
use_srv_name: false
Loading

0 comments on commit 55d27ec

Please sign in to comment.