Skip to content

Commit

Permalink
🐛 [patch] Fix RPC unauthorized error (#2)
Browse files Browse the repository at this point in the history
* 🐛 Fix RPC unauthorized error

* 🍱 Add logs permission

* 🐛 Fix licence badge

* 🐛 Fix links
  • Loading branch information
zinref authored Mar 19, 2020
1 parent a44c719 commit 0f26802
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 73 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Samsahai (S2H)
[![CircleCI](https://circleci.com/gh/agoda-com/samsahai.svg?style=svg)](https://circleci.com/gh/agoda-com/samsahai) ![Samsahai](https://github.com/agoda-com/samsahai/workflows/Samsahai/badge.svg) [![codecov](https://codecov.io/gh/agoda-com/samsahai/branch/master/graph/badge.svg?token=mt0oLjFy0k)](https://codecov.io/gh/agoda-com/samsahai) [![Docker Repository on Quay](https://quay.io/repository/samsahai/samsahai/status "Docker Repository on Quay")](https://quay.io/repository/samsahai/samsahai) ![GitHub](https://img.shields.io/github/license/agoda-com/samsahai)

[![CircleCI](https://circleci.com/gh/agoda-com/samsahai.svg?style=svg)](https://circleci.com/gh/agoda-com/samsahai)
![Samsahai](https://github.com/agoda-com/samsahai/workflows/Samsahai/badge.svg)
[![codecov](https://codecov.io/gh/agoda-com/samsahai/branch/master/graph/badge.svg?token=mt0oLjFy0k)](https://codecov.io/gh/agoda-com/samsahai)
[![Docker Repository on Quay](https://quay.io/repository/samsahai/samsahai/status "Docker Repository on Quay")](https://quay.io/repository/samsahai/samsahai)
[![License](https://img.shields.io/badge/Licence-Apache%202.0-blue.svg)](./LICENSE)

Dependencies verification system with Kubernetes Operator

Expand Down Expand Up @@ -249,10 +252,10 @@ After this step, you can see the result following [minikube promote new active](
## Contribution Policy
Samsahai is an open source project, and depends on its users to improve it. We are more than happy to find you are interested in taking the project forward.
Kindly refer to the [Contribution Guidelines](https://github.com/agoda-com/samsahai/blob/master/CONTRIBUTING) for detailed information.
Kindly refer to the [Contribution Guidelines](https://github.com/agoda-com/samsahai/blob/master/CONTRIBUTING.md) for detailed information.
## Code of Conduct
Please refer to [Code of Conduct](https://github.com/agoda-com/samsahai/blob/master/CODE_OF_CONDUCT) document.
Please refer to [Code of Conduct](https://github.com/agoda-com/samsahai/blob/master/CODE_OF_CONDUCT.md) document.
## License
Samsahai is open source and available under the [Apache License, Version 2.0](https://github.com/agoda-com/samsahai/blob/master/LICENSE).
1 change: 1 addition & 0 deletions config/chart/samsahai/templates/clusterrole-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rules:
- bindings
- configmaps
- limitranges
- logs
- persistentvolumeclaims
- pods
- namespaces
Expand Down
1 change: 1 addition & 0 deletions internal/samsahai/k8sobject/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func GetRole(teamComp *s2hv1beta1.Team, namespaceName string) runtime.Object {
"",
},
Resources: []string{
"logs",
"pods",
"services",
"endpoints",
Expand Down
4 changes: 2 additions & 2 deletions internal/staging/collect_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ func (c *controller) createDeploymentZipLogs(q *s2hv1beta1.Queue) (string, error
isPodStagingCtrl := strings.Contains(pod.Name, internal.StagingCtrlName)
if isPodStagingCtrl {
cmdLogStagingPod := "logs %s --tail=1000 --timestamps%s"
podLog := execCommand("kubectl",
podStagingCtrlLog := execCommand("kubectl",
strings.Split(fmt.Sprintf(cmdLogStagingPod, pod.Name, extraArg), " ")...)
appendFileToZip(zipw, fmt.Sprintf("pod.log.%s.txt", pod.Name), podLog)
appendFileToZip(zipw, fmt.Sprintf("pod.log.%s.txt", pod.Name), podStagingCtrlLog)
continue
}

Expand Down
14 changes: 13 additions & 1 deletion internal/staging/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package staging
import (
"context"
"fmt"
"net/http"
"time"

"github.com/pkg/errors"
"github.com/twitchtv/twirp"

s2hv1beta1 "github.com/agoda-com/samsahai/api/v1beta1"
"github.com/agoda-com/samsahai/internal"
Expand Down Expand Up @@ -127,17 +129,27 @@ func (c *controller) deleteQueue(q *s2hv1beta1.Queue) error {
}

func (c *controller) updateQueueWithState(q *s2hv1beta1.Queue, state s2hv1beta1.QueueState) error {
headers := make(http.Header)
headers.Set(internal.SamsahaiAuthHeader, c.authToken)
ctx := context.TODO()
ctx, err := twirp.WithHTTPRequestHeaders(ctx, headers)
if err != nil {
return errors.Wrap(err, "cannot set request header")
}

q.SetState(state)
logger.Debug(fmt.Sprintf("queue %s/%s update to state: %s", q.GetNamespace(), q.GetName(), q.Status.State))
comp := &rpc.ComponentUpgrade{
Name: q.Spec.Name,
Namespace: q.Namespace,
}

if c.s2hClient != nil {
if _, err := c.s2hClient.SendUpdateStateQueueMetric(context.TODO(), comp); err != nil {
if _, err := c.s2hClient.SendUpdateStateQueueMetric(ctx, comp); err != nil {
logger.Error(err, "cannot send updateQueueWithState queue metric")
}
}

return c.updateQueue(q)
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/samsahai/rpc/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 17 additions & 30 deletions pkg/samsahai/rpc/service.twirp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pkg/staging/rpc/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 17 additions & 30 deletions pkg/staging/rpc/service.twirp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f26802

Please sign in to comment.