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

initial imagestream plugin work: logs without copying local images #1

Merged
merged 1 commit into from
Mar 22, 2019

Conversation

sseago
Copy link
Contributor

@sseago sseago commented Mar 20, 2019

This includes the basic logic needed for the backup plugin. The skopeo log
statements will be replaced with actual image copying once the skopeo
code is made available, and the necessary velero validation changes to support
the shared s3-backed registry are put in place.

Copy link

@arapov arapov left a comment

Choose a reason for hiding this comment

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

I guess it looks good to me with minor changes.
Also I would use empty lines to split the blocks within the functions for better readability, e.g:

func (p *BackupPlugin) coreClient() (*corev1.CoreV1Client, error) {
	config, err := rest.InClusterConfig()
	if err != nil {
		return nil, err
	}

	client, err := corev1.NewForConfig(config)
	if err != nil {
		return nil, err
	}
	
	return client, nil
}

I didn't jump into p.Log.Info() facility, so I can be wrong... But I feel like we may want to use it to report errors too.

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"

"github.com/heptio/velero/pkg/apis/velero/v1"
Copy link

@arapov arapov Mar 21, 2019

Choose a reason for hiding this comment

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

I would also change this to
v1 "github.com/heptio/velero/pkg/apis/velero/v1"

it makes easier for me to navigate through */v1 imports later...

type imagePolicyConfig struct {
InternalRegistryHostname string `json:"internalRegistryHostname"`
}
type ApiServerConfig struct {
Copy link

Choose a reason for hiding this comment

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

Do we want this exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I copied this bit from one of the other plugin files. I suspect we either want this not exported, or we want it exported and shared among the plugin files. @dymurray what do you think?

}
}
return nil
}
Copy link

Choose a reason for hiding this comment

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

findSpecTag idented with spaces instead of tabs. It must be tabs, unless required we have a strong reason for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. There's no reason for this. It happened because I pasted and modified the code from elsewhere and I didn't notice the indent problem in my editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And yeah, I'd forgotten about gofmt.

}
}
return nil
}
Copy link

Choose a reason for hiding this comment

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

ditto. same comment as for findSpecTag applies


}
return internalRegistry, nil
} else if strings.HasPrefix(ocpVersion, "4.") {
Copy link

Choose a reason for hiding this comment

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

unneeded extra space after if. @sseago you may want to run gofmt and golint before creating pull requests.


func findStatusTag(tags []imagev1API.NamedTagEventList, name string) (*imagev1API.NamedTagEventList) {
for _, tag := range tags {
if tag.Tag==name {
Copy link

Choose a reason for hiding this comment

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

add spaces around ==

internalRegistry := registrySvc.Spec.ClusterIP
if registrySvc.Spec.Ports[0].Port != 80 {
internalRegistry = internalRegistry + ":" + strconv.Itoa(int(registrySvc.Spec.Ports[0].Port))

Copy link

Choose a reason for hiding this comment

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

remove newline

@sseago
Copy link
Contributor Author

sseago commented Mar 21, 2019

@arapov OK, I fixed the gofmt issues. We still need to resolve the ApiServerConfig export question. Regarding the logging, I know that passing the error back causes velero to log the error message along with failing the backup/restore. Perhaps we also want to add a separate log message from the plugin here? @dymurray what do you think? Is it just extra code that duplicates messages, or is there some value in seeing the error log message from the plugin directly?

Copy link
Contributor

@dymurray dymurray left a comment

Choose a reason for hiding this comment

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

Looks great to me. I noticed you use len(string) to check for empty strings. I think doing that and doing if string != "" is both used in golangs string libraries so good with me.

return "", err
}
internalRegistry := registrySvc.Spec.ClusterIP
if registrySvc.Spec.Ports[0].Port != 80 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we checking to ensure it's not port 80 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I think 1) 80 may be the wrong port anyway and 2) it's probably unnecessary. I was trying to account for the case where the dockerImageReferences in the local registry were missing the (optional) port number, but I haven't actually seen any cases where this is true. Even if you use an exposed route for the registry and push/tag externally using this route path (without a port), internally the :5000 gets added, at least from what I've seen. I'll remove the check here and assume the port will always be shown. This is only relevant for 3.x anyway, as for 4.x we can pull the registry path directly from the configMap.

@dymurray
Copy link
Contributor

@sseago Re: error messages, since you are still developing on this I don't mind having the extra error messages since it helps debugging. Long term I say remove them and use velero's log message when you return the error.

@arapov
Copy link

arapov commented Mar 21, 2019

Looks great to me. I noticed you use len(string) to check for empty strings. I think doing that and doing if string != "" is both used in golangs string libraries so good with me.

Both are indeed valid, though I would keep the way the code is more clear and gives context. For instance, if we want to look at element x then len(string) > x, even for x == 0 and if we care about "this very specific string" then write string == "".
Also I remember folks were comparing against len() in the past due to compiler optimization. Since 2011 or so it is not true anymore. I'd prefer == "" here.

@sseago
Copy link
Contributor Author

sseago commented Mar 21, 2019

Both are indeed valid, though I would keep the way the code is more clear and gives context. For instance, if we want to look at element x then len(string) > x, even for x == 0 and if we care about "this very specific string" then write string == "".

In this case, I'm just trying to do the equivalent of checking for nil. What's the clearest way of doing that for strings in go? Either len(x)==0, or x=="" works, so it's a question clarity/style.

@dymurray
Copy link
Contributor

I generally see x == "" more frequently, but go's internal strings package uses both so I am cool with either. Just a stylistic approach.

This includes the basic logic needed for the backup plugin. The skopeo log
statements will be replaced with actual image copying once the skopeo
code is made available, and the necessary velero validation changes to support
the shared s3-backed registry are put in place.
@sseago sseago merged commit feeb23f into fusor:master Mar 22, 2019
alexander-demicev pushed a commit to alexander-demicev/ocp-velero-plugin that referenced this pull request Oct 9, 2019
General velero plugin implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants