Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Find conflicting fields programatically #111

Closed
3 tasks
concaf opened this issue Jul 5, 2017 · 3 comments
Closed
3 tasks

Find conflicting fields programatically #111

concaf opened this issue Jul 5, 2017 · 3 comments
Assignees
Milestone

Comments

@concaf
Copy link
Collaborator

concaf commented Jul 5, 2017

We embed a lot of structs (huuuge structs), and it's very likely that there are some conflicting fields which we cannot catch just by looking.

We need to way to find conflicting fields in our resulting spec, and then handle such conflicts gracefully and very reliably.

One example is while implementing jobs (#52), I figured that the activeDeadlineSeconds field would not populate in the JobSpec, and @surajssd and I figured out that this field exists in both api.PodSpec and batch.JobSpec and the way we are building jobs is -

type JobSpecMod struct {
	Name          string `json:"name,omitempty"`
	api.PodSpec   `json:",inline"`
	batch.JobSpec `json:",inline"`
}

Hence, this field does not get populated in either of the structs due to the conflict.

In this case, the conflicting field activeDeadlineSeconds specifies the number of seconds a pod is allowed to run on a node, so it makes sense to substitute the same value in both JobSpec and PodSpec.

Similarly, we need to take decisions for all the conflicting fields.

So -

  • Find conflicting fields
  • Handle conflicting fields such that the unmarshalled data for these is not lost and is stored somewhere
  • Make intelligent decision for each conflicting field based on the input data
@kadel
Copy link
Member

kadel commented Jul 11, 2017

if i understand it correctly activeDeadlineSeconds in Job is doing something slightly different than activeDeadlineSeconds in Pod. It should be possible to specify both separately

concaf added a commit to concaf/kedge that referenced this issue Jul 11, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
@kadel
Copy link
Member

kadel commented Jul 13, 2017

How do you propose to fix conflicting keys programmatically?

@concaf
Copy link
Collaborator Author

concaf commented Jul 14, 2017

@kadel I don't think the fixing can be done programmatically 😋 (renaming the issue), I think those checkboxes are more of the workflow we should follow. This issue can be closed in full with #135

@concaf concaf changed the title Find and fix conflicting fields programatically Find conflicting fields programatically Jul 14, 2017
concaf added a commit to concaf/kedge that referenced this issue Jul 19, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
@pradeepto pradeepto added this to the 0.1.0 milestone Jul 19, 2017
concaf added a commit to concaf/kedge that referenced this issue Jul 21, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
concaf added a commit to concaf/kedge that referenced this issue Jul 25, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
concaf added a commit to concaf/kedge that referenced this issue Jul 27, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
concaf added a commit to concaf/kedge that referenced this issue Jul 31, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
concaf added a commit to concaf/kedge that referenced this issue Jul 31, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes kedgeproject#111
concaf added a commit that referenced this issue Jul 31, 2017
Before this commit, we had no way to know if the embedded structs
had any conflicting fields between each other or with the struct
embedding the structs. This led to inconsistency since in case
of conflicting fields, the data would not be unmarshalled and due
to presence of a lot of fields, this would go unnoticed.

This commit handles this in a 4 step process.

Step 1: Get all the target structs.
Look at tags in the fields of the input struct as well as the embedded
structs, so both of them become our target structs.

Step 2: Get blacklisted tags.
Get the fields which have already been handled and were previously
conflicting. This needs to be done only for the structs in spec.go,
and with fields marked as "conflicting" using a JSON tag

Step 3: Get JSON tags from target structs.
Get the JSON tags from all of the target structs which we got in Step 1
except for the blacklisted tags, along with the names of the structs
which hold the field with that tag.

Step 4: Check if more than one struct holds a tag.
Delete all the tags in Step 3 which are only help by one struct, because
it means that the JSON tag is not conficting, and finally return the
remaining tags which are held by more than one struct, and are not
handled, hence conflicting tags

The code has been heavily documented, and tests have been added for this
behavior.

The entire code is not a part of the main program and is not run every
time a user executes any kedge command, instead it has been put as a
test, since it's more of a developer facing problem than a user facing
one.

Fixes #111
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants