-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: labelling resources #250
Changes from 3 commits
069767e
5dfb4cc
3fb525f
161d57b
fb46880
0f23bd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,13 @@ func (m Metadata) Labels() map[string]interface{} { | |
return m["labels"].(map[string]interface{}) | ||
} | ||
|
||
func (m Metadata) SetLabel(key, value string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need that, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m.Labels() does return a new map, but it does not assign it back into But if we are going toward the "just do it" approach to labelling, that is not a concern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I mixed up code in my head, I changed it in my PR so it creates AND returns if nil. I'd go forward like so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically |
||
if !m.HasLabels() { | ||
m["labels"] = make(map[string]interface{}) | ||
} | ||
m["labels"].(map[string]interface{})[key] = value | ||
} | ||
|
||
// HasAnnotations returns whether the manifest has annotations | ||
func (m Metadata) HasAnnotations() bool { | ||
return m2o(m).Get("annotations").IsMSI() | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -47,8 +47,10 @@ func Parse(data []byte, name string) (*v1alpha1.Config, error) { | |||||||
return nil, errors.Wrap(err, "parsing spec.json") | ||||||||
} | ||||||||
|
||||||||
// set the name field | ||||||||
config.Metadata.Name = name | ||||||||
// set the name field if not given in spec | ||||||||
if config.Metadata.Name == "" { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was unsure about this change. The spec files have a name in them, but it was being overwritten with the directory path which is an invalid label. I need to understand the context here better on why we were overwriting it in the first place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do it this way. The filepath is Tanka's source of truth. Instead, just sanitize the filepath, by substituting all tanka/pkg/spec/v1alpha1/config.go Lines 38 to 40 in 2f61573
The fact we have names in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, makes sense... sort of. I guess it does root the file system at the ksonnet folder somehow, so that helps it be deterministic I suppose. |
||||||||
config.Metadata.Name = name | ||||||||
} | ||||||||
|
||||||||
if err := handleDeprecated(config, data); err != nil { | ||||||||
return config, err | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,24 @@ func parse(dir string, opts *options) (*ParseResult, error) { | |
return nil, errors.Wrap(err, "reconciling") | ||
} | ||
|
||
if opts.applyLabels { | ||
applyLabels(rec, env) | ||
} | ||
|
||
return &ParseResult{ | ||
Resources: rec, | ||
Env: env, | ||
}, nil | ||
} | ||
|
||
func applyLabels(state manifest.List, env *v1alpha1.Config) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not belong here, it should be part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I'd prefer not to have functions that modify their input variables. Given this is fairly short, just put it into |
||
for _, manifest := range state { | ||
meta := manifest.Metadata() | ||
meta.SetLabel("app.kubernetes.io/managed-by", "tanka") | ||
meta.SetLabel("tanka.dev/environment", env.Metadata.Name) | ||
} | ||
} | ||
|
||
// eval returns the raw evaluated Jsonnet and the parsed env used for evaluation | ||
func eval(dir string, extCode map[string]string) (raw map[string]interface{}, env *v1alpha1.Config, err error) { | ||
baseDir, env, err := loadDir(dir) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having this as a feature flag sounds dangerous – people will forget to pass it, resulting in unset labels for subsets of resources. I see two options here:
spec.json
. See my original pruning PR for that:tanka/pkg/spec/v1alpha1/config.go
Line 47 in 2f61573
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna go with 1. I did intend to switch from opt-in to opt-out at some point in the future, but honestly this is either something that should be done or it isn't.