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

Centralized Longterm workflow persistence storage #1344

Merged
merged 42 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
00f08b1
CheckandEstimate implementation
sarabala1979 Apr 4, 2019
e7ac42a
fixed variable rename
sarabala1979 Apr 4, 2019
d956bfc
fixed gofmt
sarabala1979 Apr 5, 2019
be9b3b5
fixed feedbacks
sarabala1979 Apr 5, 2019
0d15503
merge
sarabala1979 Apr 9, 2019
d967df3
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Apr 9, 2019
4c9b645
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Apr 10, 2019
c40cc5f
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Apr 11, 2019
759b046
Centralized Longterm workflow persistence storage implementaion
sarabala1979 Apr 25, 2019
7b6e91b
enable postgres config
sarabala1979 Apr 26, 2019
d2bbe7a
fixed style
sarabala1979 Apr 26, 2019
2de02e8
Added error check
sarabala1979 Apr 26, 2019
51e2d5f
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Apr 26, 2019
5f41f3e
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 May 9, 2019
a220ae5
Incorporated review comments
sarabala1979 May 21, 2019
9e2ad85
Update workflowRepository.go
sarabala1979 May 21, 2019
d84f960
fixed style
sarabala1979 May 21, 2019
b4baed5
fixed style -1
sarabala1979 May 21, 2019
1268208
fixed file name
sarabala1979 May 21, 2019
acfe894
updated
sarabala1979 May 21, 2019
4fc4394
Update workflow_repository.go
sarabala1979 May 21, 2019
18a7e54
Update workflow_repository.go
sarabala1979 May 22, 2019
8eb6ea9
Merge branch 'master' into Issue745
sarabala1979 May 31, 2019
6c0e87b
Update util.go
sarabala1979 May 31, 2019
3654958
Update util.go
sarabala1979 May 31, 2019
f39170e
Update workflow_repository.go
sarabala1979 May 31, 2019
6e027fb
Update swagger.json
sarabala1979 May 31, 2019
9a95a48
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 May 31, 2019
6a080b5
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Jun 7, 2019
0a48649
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Jun 11, 2019
7b273ab
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Jun 17, 2019
7b45549
Merge branch 'master' into Issue745
sarabala1979 Jun 18, 2019
dbe9393
Merge branch 'Issue745'
sarabala1979 Jun 18, 2019
d9f330e
Merge branch 'master' into Issue745
sarabala1979 Jun 18, 2019
925937b
Merge branch 'master' into Issue745
sarabala1979 Jun 19, 2019
e833c99
Update config.go
sarabala1979 Jun 19, 2019
f0b875a
fixed the comments
sarabala1979 Jun 25, 2019
49b931e
Update workflow_repository.go
sarabala1979 Jun 25, 2019
0f43598
Update DBRepository.go
sarabala1979 Jun 25, 2019
4ee83de
Update DBRepository.go
sarabala1979 Jun 26, 2019
03565ff
Renamed few variable
sarabala1979 Jun 26, 2019
dc583c2
Update .gitignore
sarabala1979 Jun 28, 2019
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
76 changes: 76 additions & 0 deletions Gopkg.lock

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

5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ required = [
[[constraint]]
name = "gopkg.in/jcmturner/gokrb5.v5"
version = "5.3.0"

[[constraint]]
name = "upper.io/db.v3"
version ="3.5.7"

27 changes: 20 additions & 7 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (

// Externally visible error codes
const (
CodeUnauthorized = "ERR_UNAUTHORIZED"
CodeBadRequest = "ERR_BAD_REQUEST"
CodeForbidden = "ERR_FORBIDDEN"
CodeNotFound = "ERR_NOT_FOUND"
CodeNotImplemented = "ERR_NOT_IMPLEMENTED"
CodeTimeout = "ERR_TIMEOUT"
CodeInternal = "ERR_INTERNAL"
CodeUnauthorized = "ERR_UNAUTHORIZED"
CodeBadRequest = "ERR_BAD_REQUEST"
CodeForbidden = "ERR_FORBIDDEN"
CodeNotFound = "ERR_NOT_FOUND"
CodeNotImplemented = "ERR_NOT_IMPLEMENTED"
CodeTimeout = "ERR_TIMEOUT"
CodeInternal = "ERR_INTERNAL"
CodeDBUpdateRowNotFound = "ERR_DB_UPDATE_ROW_NOT_FOUND"
Copy link
Member

Choose a reason for hiding this comment

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

The errors package is supposed to be very generic. Generic enough so that it would be potentially be put into the argo/pkg library. ERR_DB_UPDATE_ROW_NOT_FOUND is too specific of an error to include here. Can we find another way to handle this?

Copy link
Member

Choose a reason for hiding this comment

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

Further review shows that the way that we use this code is to implement Upsert. But that is an implementation detail of the sqldb package to implement Save(). This should be handled there and errors package should not be touched.

)

// ArgoError is an error interface that additionally adds support for
Expand Down Expand Up @@ -78,6 +79,18 @@ func InternalWrapErrorf(err error, format string, args ...interface{}) error {
return Wrap(err, CodeInternal, fmt.Sprintf(format, args...))
}

func DBUpdateNoRowFoundError(err error, message ...string) error {
if len(message) == 0 {
return Wrap(err, CodeDBUpdateRowNotFound, err.Error())
}
return Wrap(err, CodeDBUpdateRowNotFound, message[0])
}

// InternalWrapErrorf annotates the error with the ERR_INTERNAL code and a stack trace, optional message
func IDBUpdateNoRowFoundErrorf(err error, format string, args ...interface{}) error {
return Wrap(err, CodeDBUpdateRowNotFound, fmt.Sprintf(format, args...))
}

// Wrap returns an error annotating err with a stack trace at the point Wrap is called,
// and a new supplied message. The previous original is preserved and accessible via Cause().
// If err is nil, Wrap returns nil.
Expand Down
47 changes: 47 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package util

import (
"fmt"
"github.com/argoproj/argo/errors"
"github.com/argoproj/argo/util/retry"
"github.com/prometheus/common/log"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
)

type Closer interface {
Close() error
}
Expand All @@ -9,3 +20,39 @@ type Closer interface {
func Close(c Closer) {
_ = c.Close()
}

// GetSecrets retrieves a secret value and memoizes the result
func GetSecrets(clientSet kubernetes.Interface, namespace, name, key string) ([]byte, error) {
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved

secretMaps := make(map[string][]byte)

cachedKey := fmt.Sprintf("%s/%s/%s", namespace, name, key)

secretsIf := clientSet.CoreV1().Secrets(namespace)
var secret *apiv1.Secret
var err error
_ = wait.ExponentialBackoff(retry.DefaultRetry, func() (bool, error) {
secret, err = secretsIf.Get(name, metav1.GetOptions{})
if err != nil {
log.Warnf("Failed to get secret '%s': %v", name, err)
if !retry.IsRetryableKubeAPIError(err) {
return false, err
}
return false, nil
}
return true, nil
})
if err != nil {
return []byte{}, errors.InternalWrapError(err)
}
// memoize all keys in the secret since it's highly likely we will need to get a
// subsequent key in the secret (e.g. username + password) and we can save an API call
for k, v := range secret.Data {
secretMaps[fmt.Sprintf("%s/%s/%s", namespace, name, k)] = v
}
val, ok := secretMaps[cachedKey]
if !ok {
return []byte{}, errors.Errorf(errors.CodeBadRequest, "secret '%s' does not have the key '%s'", name, key)
}
return val, nil
}
Loading