Skip to content
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

Mirror keystore & secretstore #3411

Merged
merged 3 commits into from
Oct 1, 2017

Conversation

justinsb
Copy link
Member

This allows us to have our API objects in kops-server, but our
configuration on S3 or GCS.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 17, 2017
@justinsb
Copy link
Member Author

Builds on #3409

@justinsb justinsb force-pushed the mirror_stores branch 3 times, most recently from be3755e to 0636e65 Compare September 18, 2017 03:46
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 19, 2017
@k8s-github-robot
Copy link

@justinsb PR needs rebase

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2017
@k8s-github-robot
Copy link

@justinsb PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2017
@justinsb justinsb force-pushed the mirror_stores branch 2 times, most recently from bc8b5e8 to 555bdd0 Compare September 24, 2017 01:15
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 24, 2017
This allows us to have our API objects in kops-server, but our
configuration on S3 or GCS.
Copy link
Contributor

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of questions. How are we keeping these in sync? What is the basic premise you are using?

@@ -225,6 +228,9 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
cmd.Flags().StringVar(&options.Target, "target", options.Target, "Target - direct, terraform, cloudformation")
cmd.Flags().StringVar(&options.Models, "model", options.Models, "Models to apply (separate multiple models with commas)")

// Configuration / state location
cmd.Flags().StringVar(&options.ConfigBase, "config-base", options.ConfigBase, "The location where the cluster state files should be stored")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this differ from the state store? I am concerned a n00b would be confused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Slack

@justinsb [5:02 PM]
So if you set a different config-base, you can have the objects that the cluster reads be different from the state store

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm actually going to feature-flag it, and probably tie to it kops-server initially.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I also reworked the description a little, but it's a tricky concept)

return fi.NewVFSCAStore(basedir), nil
}

func DeleteAllClusterState(basePath vfs.Path) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to test this in a subfolder state store without list perms. I will open an issue for me.

Copy link
Member Author

@justinsb justinsb Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was moved from pkg/apis/kops/registry

continue
}

return fmt.Errorf("refusing to delete: unknown file found: %s", path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return fmt.Errorf("refusing to delete: unknown file found: %s", path)

how about

return fmt.Errorf("unknown file found %q, not deleting: %q", path, basePath)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the existing code, the point is that we do a kops delete cluster and we refuse to delete anything, because we can't prove it safe. That's what the first message is trying to imply (and I think the proposed alternative does not capture)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current message makes sense 👍

Disregard my comment

// FederationsFor implements the FederationsFor method of Clientset for a kubernetes-API state store
func (c *RESTClientset) FederationsFor(federation *kops.Federation) kopsinternalversion.FederationInterface {
// Unsure if this should be namespaced or not - probably, so that we can RBAC it...
panic("Federations are currently not supported by the server API")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic ouch. We do not do that in many places. You want the server to restart?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a panic because there's no error code here, and because we don't expect people to be using Federations. I'd say panic is appropriate - our code should be crash-safe.

defaultReadVersion := v1alpha1.SchemeGroupVersion.WithKind(kind)
r.defaultReadVersion = &defaultReadVersion
r.validate = func(o runtime.Object) error {
return validation.ValidateInstanceGroup(o.(*kops.InstanceGroup))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test if o.(*kops.InstanceGroup) is a *kops.InstanceGroup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it would be a bug, and panic-ing is appropriate here

return fi.DefaultDeltaRunMethod(e, c)
}

func (s *MirrorKeystore) CheckChanges(a, e, changes *MirrorKeystore) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we code comments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can put the normal CheckChanges implements Task::CheckChanges.

}

func (e *MirrorSecrets) Find(c *fi.Context) (*MirrorSecrets, error) {
// TODO:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO what?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will expand

@@ -36,8 +36,11 @@ type SecretStore interface {
// ListSecrets lists the ids of all known secrets
ListSecrets() ([]string, error)

// VFSPath returns the path where the SecretStore is stored
VFSPath() vfs.Path
//// VFSPath returns the path where the SecretStore is stored
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code please


primary := fi.FindPrimary(keyset)
if primary == nil {
glog.Warningf("skipping secret with no primary data: %s", keyset.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we have no primary data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be unexpected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then go boom please ... fmt.Error or panic


return vfs.CopyTree(c.basedir, basedir)
//
//files, err := c.basedir.ReadDir()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we kill commented code please?

@chrislovecnm
Copy link
Contributor

If you could take a look at the err's that are not returned with fmt please. We have ALOT in this code.

Copy link
Contributor

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments about fmt

for _, path := range paths {
relativePath, err := vfs.RelativePath(basePath, path)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to fmt.Errorf here as the user may not know what vfs is actually doing here.


primary := FindPrimary(keyset)
if primary == nil {
glog.Warningf("skipping keyset with no primary data: %s", keyset.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fail here? What is the use case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - just being tolerant, but we don't expect this. If we see it happening for some reason (it shouldn't), then we can downgrade to a warning.

for _, srcFile := range srcFiles {
relativePath, err := RelativePath(src, srcFile)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find RelativePath in your source tree. github search is not being kind. You call if it would be helpful to fmt.Errorf more in here.

@justinsb
Copy link
Member Author

justinsb commented Sep 30, 2017

How are we keeping these in sync?

The MirrorKeystore and MirrorSecrets tasks copy them, to keep these in sync.

@justinsb
Copy link
Member Author

justinsb commented Sep 30, 2017

RelativePath is here:

kops/util/pkg/vfs/vfs.go

Lines 69 to 82 in 8585f00

func RelativePath(base Path, child Path) (string, error) {
basePath := base.Path()
childPath := child.Path()
if !strings.HasSuffix(basePath, "/") {
basePath += "/"
}
if !strings.HasPrefix(childPath, basePath) {
return "", fmt.Errorf("Path %q is not a child of %q", child, base)
}
relativePath := childPath[len(basePath):]
return relativePath, nil
}

My rules of thumb for when to fmt.Errof:

  • If we're calling our function, we don't need fmt.Errorf - we should return good errors
  • If we're calling a library function we probably should fmt.Errorf - we shouldn't assume anyone else returns good errors
  • If we have extra context, we can fmt.Errorf (even on our code)
  • Because of the lack of stack-traces on errors, sometimes we do have to leave breadcrumbs with an otherwise unnecessary fmt.Errorf. Probably more when we're calling into functions that are complicated, than a simpler function like RelativePath.

@chrislovecnm
Copy link
Contributor

I am copying what you wrote and putting in in an issue, we probably should have that in the developer guide. I do a bit more cause we don't have stack exceptions. Or log the error.

@justinsb
Copy link
Member Author

justinsb commented Oct 1, 2017

Put in fixes as suggested - thanks!

@chrislovecnm
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 1, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrislovecnm

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 1, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue.

@k8s-github-robot k8s-github-robot merged commit 0905e71 into kubernetes:master Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants