-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
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 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.
velero-plugins/imagestream/backup.go
Outdated
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" |
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 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...
velero-plugins/imagestream/backup.go
Outdated
type imagePolicyConfig struct { | ||
InternalRegistryHostname string `json:"internalRegistryHostname"` | ||
} | ||
type ApiServerConfig struct { |
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.
Do we want this exported?
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.
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 | ||
} |
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.
findSpecTag idented with spaces instead of tabs. It must be tabs, unless required we have a strong reason for this.
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.
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.
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.
And yeah, I'd forgotten about gofmt.
} | ||
} | ||
return nil | ||
} |
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.
ditto. same comment as for findSpecTag applies
velero-plugins/imagestream/backup.go
Outdated
|
||
} | ||
return internalRegistry, nil | ||
} else if strings.HasPrefix(ocpVersion, "4.") { |
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.
unneeded extra space after if. @sseago you may want to run gofmt and golint before creating pull requests.
velero-plugins/imagestream/backup.go
Outdated
|
||
func findStatusTag(tags []imagev1API.NamedTagEventList, name string) (*imagev1API.NamedTagEventList) { | ||
for _, tag := range tags { | ||
if tag.Tag==name { |
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.
add spaces around ==
velero-plugins/imagestream/backup.go
Outdated
internalRegistry := registrySvc.Spec.ClusterIP | ||
if registrySvc.Spec.Ports[0].Port != 80 { | ||
internalRegistry = internalRegistry + ":" + strconv.Itoa(int(registrySvc.Spec.Ports[0].Port)) | ||
|
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.
remove newline
66ab0c1
to
04ef725
Compare
@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? |
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.
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.
velero-plugins/imagestream/backup.go
Outdated
return "", err | ||
} | ||
internalRegistry := registrySvc.Spec.ClusterIP | ||
if registrySvc.Spec.Ports[0].Port != 80 { |
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.
Why are we checking to ensure it's not port 80 here?
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.
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.
@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. |
04ef725
to
7efbce4
Compare
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 |
I generally see |
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.
7efbce4
to
55dafef
Compare
General velero plugin implementation
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.