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

Support for User Links add through annotations for Pods and Services #2249

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/app/backend/userlinks/userlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ func GetUserLinks(client k8sClient.Interface, namespace, name, resource, host st
func getServiceLinks(client k8sClient.Interface, namespace, name, host string) ([]UserLink, error) {
userLinks := []UserLink{}
service, err := client.CoreV1().Services(namespace).Get(name, metaV1.GetOptions{})
if err != nil {
return userLinks, err
}
if len(service.Annotations[annotationObj]) == 0 {
if err != nil || len(service.Annotations[annotationObj]) == 0 {
return userLinks, err
}
Copy link
Member

@maciaszczykm maciaszczykm Sep 13, 2017

Choose a reason for hiding this comment

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

Merge both ifs to err != nil || len(pod.Annotations[annotationObj]) == 0.

Copy link
Member

Choose a reason for hiding this comment

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

getServiceLinks and getPodLinks have a lot in common. Perhaps you could avoid such code duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried but they differ enough so that it makes it not worth refactoring further.

m := map[string]string{}
Expand All @@ -90,7 +87,7 @@ func getServiceLinks(client k8sClient.Interface, namespace, name, host string) (
userLink.Valid = true
} else if strings.Contains(val, apiserverProxyURL) { //dealing with relative path
//strip the url of apiserver-proxy-url
userLink.Link = host + "/api/" + "v1" + "/namespaces/" + service.ObjectMeta.Namespace +
userLink.Link = host + "/api/v1/namespaces/" + service.ObjectMeta.Namespace +
Copy link
Contributor

Choose a reason for hiding this comment

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

in my understanding the host is replaced later on in the frontend. So could we use a static placeholder, like localhost?

"/services/" + service.ObjectMeta.Name + "/proxy" + strings.TrimLeft(val, apiserverProxyURL)
userLink.Valid = true
} else {
Expand All @@ -106,10 +103,7 @@ func getServiceLinks(client k8sClient.Interface, namespace, name, host string) (
func getPodLinks(client k8sClient.Interface, namespace, name, host string) ([]UserLink, error) {
userLinks := []UserLink{}
pod, err := client.CoreV1().Pods(namespace).Get(name, metaV1.GetOptions{})
if err != nil {
return userLinks, err
}
if len(pod.Annotations[annotationObj]) == 0 {
if err != nil || len(pod.Annotations[annotationObj]) == 0 {
return userLinks, err
}
Copy link
Member

Choose a reason for hiding this comment

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

Merge both ifs to err != nil || len(pod.Annotations[annotationObj]) == 0 .


Expand All @@ -125,7 +119,7 @@ func getPodLinks(client k8sClient.Interface, namespace, name, host string) ([]Us
//use api server proxy url
if strings.Contains(val, apiserverProxyURL) {
//strip the url of apiserver-proxy-url
userLink.Link = host + "/api/" + "v1" + "/namespaces/" + pod.ObjectMeta.Namespace +
userLink.Link = host + "/api/v1/namespaces/" + pod.ObjectMeta.Namespace +
"/pods/" + pod.ObjectMeta.Name + "/proxy" + strings.TrimLeft(val, apiserverProxyURL)
userLink.Valid = true
} else if strings.Contains(val, "http://") { //dealing with absolute path
Expand Down
1 change: 1 addition & 0 deletions src/app/frontend/common/components/endpoint/endpoint.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
height: inherit;
margin: 0;
vertical-align: middle;
padding: 5px;
Copy link
Member

Choose a reason for hiding this comment

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

Use 0.5 * $baseline-grid as we always try to be dependent of this variable.

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
layout
layout-align="start center">
<kd-middle-ellipsis display-string="{{::link.description}} - {{::link.link}}">
</kd-middle-ellipsis>&nbsp;
</kd-middle-ellipsis>
<md-icon class="kd-endpoint-icon">open_in_new</md-icon>
</a>
</div>
Expand Down