-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Backend]Cache - Cache logic with db interaction #3266
Merged
Merged
Changes from 64 commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
6994984
Initial execution cache
rui5i 19a61e7
Add initial server logic
rui5i 0448a12
Add const
rui5i d2fad48
Change folder name
rui5i c561ca4
Change execution key name
rui5i 55ee8a7
Fix unit test
rui5i 0f83144
Add Dockerfile and OWNERS file
rui5i 1ecc855
fix go.sum
rui5i 1b5b681
Add local deployment scripts
rui5i 83126c7
Merge branch 'execution_cache' of https://github.com/rui5i/pipelines …
rui5i ae472d7
refactor src code
rui5i 8c0cac8
Add standalone deployment scripts and yamls
rui5i cb075b2
Minor fix
rui5i 4b0831a
Add execution cache image build in test folder
rui5i e1bedf7
Merge branch 'master' into execution_cache
rui5i ed1aa0e
fix test cloudbuild
rui5i 3b1323c
Fix cloudbuild
rui5i da3eb42
Add execution cache deployer image to test folder
rui5i 37521ec
Add copyright
rui5i 5efe589
Fix deployer build
rui5i fa12c40
Add license for execution cache and cloudbuild for execution cache
rui5i 3c302af
Refactor license intermediate data
rui5i 17f714e
Fix execution cache image manifest
rui5i 79e4711
Typo fix for cache and cache deployer images
rui5i a16335c
Add arguments in ca generation scripts and change deployer base image…
rui5i bb796c1
minor fix
rui5i db797b3
fix arg
rui5i 57523c0
Mirror source code with MPL in execution_cache image
rui5i 893e8b1
Minor fix
rui5i 851ce25
minor refactor on error handling
rui5i 1720ee6
Refactor cache source code, Docker image and manifest
rui5i f482c9f
Fix variable names
rui5i 6523570
Add images in .release.cloudbuild.yaml
rui5i 5c5298e
resolve merge conflict
rui5i 914d9fd
Change execution_cache to generic name
rui5i 4e7e3a9
revice readme
rui5i ad560f4
Move deployer job out of upgrade script
rui5i ba26e48
fix tests
rui5i 065af7a
fix tests
rui5i a8aa15c
Seperate cache service and cache deployer job
rui5i e7aefad
mysql set up
rui5i d3e2755
wip
rui5i e986ca1
WIP
rui5i 2df1c48
WIP
rui5i 16b3e6d
work mysql connection
rui5i 243307a
initial cache logic
rui5i da75b68
watcher
rui5i d79e909
WIP pod watching with mysql
rui5i 980f089
worked crud
rui5i c0cf37e
Add sql unit test
rui5i 616e968
Merge upstream master
rui5i 25f0bcd
fix manifest
rui5i ca41d77
Add copyright
rui5i 2b39036
Add watcher check and update cache key generation logic
rui5i 28c77c0
test replace container images
rui5i 8f987d9
work cache service
rui5i 7e19564
Add configmap for cache service
rui5i f82b781
refactor
rui5i db9bc4e
fix manifest
rui5i 4c49458
Add unit tests
rui5i c4ad659
Remove delete table
rui5i 26c790d
Fix sql dialect
rui5i f702714
Add cached step log
rui5i 14d05c0
Add metadata execution id
rui5i db1073b
minor fix
rui5i 154d26e
revert go.mod and go.sum
rui5i 901a7d2
revert go.sum and go.mod
rui5i c2156e6
revert go.sum and go.mod
rui5i 075d255
revert go.mod and go.sum
rui5i File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package client | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cenkalti/backoff" | ||
"github.com/golang/glog" | ||
"github.com/pkg/errors" | ||
"k8s.io/client-go/kubernetes" | ||
v1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type KubernetesCoreInterface interface { | ||
PodClient(namespace string) v1.PodInterface | ||
} | ||
|
||
type KubernetesCore struct { | ||
coreV1Client v1.CoreV1Interface | ||
} | ||
|
||
func (c *KubernetesCore) PodClient(namespace string) v1.PodInterface { | ||
return c.coreV1Client.Pods(namespace) | ||
} | ||
|
||
func createKubernetesCore() (KubernetesCoreInterface, error) { | ||
restConfig, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to initialize kubernetes client.") | ||
} | ||
|
||
clientSet, err := kubernetes.NewForConfig(restConfig) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to initialize kubernetes client set.") | ||
} | ||
return &KubernetesCore{clientSet.CoreV1()}, nil | ||
} | ||
|
||
// CreateKubernetesCoreOrFatal creates a new client for the Kubernetes pod. | ||
func CreateKubernetesCoreOrFatal(initConnectionTimeout time.Duration) KubernetesCoreInterface { | ||
var client KubernetesCoreInterface | ||
var err error | ||
var operation = func() error { | ||
client, err = createKubernetesCore() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
b := backoff.NewExponentialBackOff() | ||
b.MaxElapsedTime = initConnectionTimeout | ||
err = backoff.Retry(operation, b) | ||
|
||
if err != nil { | ||
glog.Fatalf("Failed to create pod client. Error: %v", err) | ||
} | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package client | ||
|
||
import ( | ||
"github.com/kubeflow/pipelines/backend/src/common/util" | ||
v1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
) | ||
|
||
type FakeKuberneteCoreClient struct { | ||
podClientFake *FakePodClient | ||
} | ||
|
||
func (c *FakeKuberneteCoreClient) PodClient(namespace string) v1.PodInterface { | ||
if len(namespace) == 0 { | ||
panic(util.NewResourceNotFoundError("Namespace", namespace)) | ||
} | ||
return c.podClientFake | ||
} | ||
|
||
func NewFakeKuberneteCoresClient() *FakeKuberneteCoreClient { | ||
return &FakeKuberneteCoreClient{&FakePodClient{}} | ||
} | ||
|
||
type FakeKubernetesCoreClientWithBadPodClient struct { | ||
podClientFake *FakeBadPodClient | ||
} | ||
|
||
func NewFakeKubernetesCoreClientWithBadPodClient() *FakeKubernetesCoreClientWithBadPodClient { | ||
return &FakeKubernetesCoreClientWithBadPodClient{&FakeBadPodClient{}} | ||
} | ||
|
||
func (c *FakeKubernetesCoreClientWithBadPodClient) PodClient(namespace string) v1.PodInterface { | ||
return c.podClientFake | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package client | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/golang/glog" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/api/policy/v1beta1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type FakePodClient struct { | ||
watchIsCalled bool | ||
patchIsCalled bool | ||
} | ||
|
||
func (FakePodClient) Create(*corev1.Pod) (*corev1.Pod, error) { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil, nil | ||
} | ||
|
||
func (FakePodClient) Update(*corev1.Pod) (*corev1.Pod, error) { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil, nil | ||
} | ||
|
||
func (FakePodClient) UpdateStatus(*corev1.Pod) (*corev1.Pod, error) { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil, nil | ||
} | ||
|
||
func (FakePodClient) Delete(name string, options *v1.DeleteOptions) error { | ||
return nil | ||
} | ||
|
||
func (FakePodClient) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil | ||
} | ||
|
||
func (FakePodClient) Get(name string, options v1.GetOptions) (*corev1.Pod, error) { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil, nil | ||
} | ||
|
||
func (FakePodClient) List(opts v1.ListOptions) (*corev1.PodList, error) { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil, nil | ||
} | ||
|
||
func (f FakePodClient) Watch(opts v1.ListOptions) (watch.Interface, error) { | ||
f.watchIsCalled = true | ||
event := watch.Event{ | ||
Type: watch.Added, | ||
Object: &corev1.Pod{}, | ||
} | ||
ch := make(chan watch.Event, 1) | ||
ch <- event | ||
return nil, nil | ||
} | ||
|
||
func (f FakePodClient) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *corev1.Pod, err error) { | ||
f.patchIsCalled = true | ||
return nil, nil | ||
} | ||
|
||
func (FakePodClient) Bind(binding *corev1.Binding) error { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil | ||
} | ||
|
||
func (FakePodClient) Evict(eviction *v1beta1.Eviction) error { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil | ||
} | ||
|
||
func (FakePodClient) GetLogs(name string, opts *corev1.PodLogOptions) *rest.Request { | ||
glog.Error("This fake method is not yet implemented.") | ||
return nil | ||
} | ||
|
||
type FakeBadPodClient struct { | ||
FakePodClient | ||
} | ||
|
||
func (FakeBadPodClient) Delete(name string, options *v1.DeleteOptions) error { | ||
return errors.New("failed to delete pod") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-sql-driver/mysql" | ||
) | ||
|
||
func CreateMySQLConfig(user, password string, mysqlServiceHost string, | ||
mysqlServicePort string, dbName string, mysqlGroupConcatMaxLen string, mysqlExtraParams map[string]string) *mysql.Config { | ||
|
||
params := map[string]string{ | ||
"charset": "utf8", | ||
"parseTime": "True", | ||
"loc": "Local", | ||
"group_concat_max_len": mysqlGroupConcatMaxLen, | ||
} | ||
|
||
for k, v := range mysqlExtraParams { | ||
params[k] = v | ||
} | ||
|
||
return &mysql.Config{ | ||
User: user, | ||
Passwd: password, | ||
Net: "tcp", | ||
Addr: fmt.Sprintf("%s:%s", mysqlServiceHost, mysqlServicePort), | ||
Params: params, | ||
DBName: dbName, | ||
AllowNativePasswords: true, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package client | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/go-sql-driver/mysql" | ||
) | ||
|
||
func TestCreateMySQLConfig(t *testing.T) { | ||
type args struct { | ||
user string | ||
password string | ||
host string | ||
port string | ||
dbName string | ||
mysqlGroupConcatMaxLen string | ||
mysqlExtraParams map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *mysql.Config | ||
}{ | ||
{ | ||
name: "default config", | ||
args: args{ | ||
user: "root", | ||
host: "mysql", | ||
port: "3306", | ||
mysqlGroupConcatMaxLen: "1024", | ||
mysqlExtraParams: nil, | ||
}, | ||
want: &mysql.Config{ | ||
User: "root", | ||
Net: "tcp", | ||
Addr: "mysql:3306", | ||
Params: map[string]string{"charset": "utf8", "parseTime": "True", "loc": "Local", "group_concat_max_len": "1024"}, | ||
AllowNativePasswords: true, | ||
}, | ||
}, | ||
{ | ||
name: "extra parameters", | ||
args: args{ | ||
user: "root", | ||
host: "mysql", | ||
port: "3306", | ||
mysqlGroupConcatMaxLen: "1024", | ||
mysqlExtraParams: map[string]string{"tls": "true"}, | ||
}, | ||
want: &mysql.Config{ | ||
User: "root", | ||
Net: "tcp", | ||
Addr: "mysql:3306", | ||
Params: map[string]string{"charset": "utf8", "parseTime": "True", "loc": "Local", "group_concat_max_len": "1024", "tls": "true"}, | ||
AllowNativePasswords: true, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := CreateMySQLConfig(tt.args.user, tt.args.password, tt.args.host, tt.args.port, tt.args.dbName, tt.args.mysqlGroupConcatMaxLen, tt.args.mysqlExtraParams); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("CreateMySQLConfig() = %#v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What are the cases where client creation can fail, but then succeed?
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 can think of cases where we deploy KFP from scratch and the mysql instance has not been ready yet. With retry here it can keep retrying until mysql instance gets ready.