forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Credentials support for S3 and GCS storage (kubeflow#94)
* Reconcile service account * Add service account/secret role binding * Add GCS secret volume * Add tests for credential reconciliation * Reorganize credential files and rename reconciler to builder
- Loading branch information
1 parent
99af0dd
commit 4f4022c
Showing
15 changed files
with
794 additions
and
48 deletions.
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
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
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
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
pkg/reconciler/ksvc/resources/credentials/gcs/gcs_secret.go
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,45 @@ | ||
/* | ||
Copyright 2019 kubeflow.org. | ||
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 | ||
http://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 gcs | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
) | ||
|
||
const ( | ||
GCSCredentialFileName = "gcloud-application-credentials.json" | ||
GCSCredentialVolumeName = "user-gcp-sa" | ||
GCSCredentialVolumeMountPath = "/var/secrets/gcloud-application-credentials.json" | ||
GCSCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS" | ||
) | ||
|
||
func BuildSecretVolume(secret *v1.Secret) (v1.Volume, v1.VolumeMount) { | ||
volume := v1.Volume{ | ||
Name: GCSCredentialVolumeName, | ||
VolumeSource: v1.VolumeSource{ | ||
Secret: &v1.SecretVolumeSource{ | ||
SecretName: secret.Name, | ||
}, | ||
}, | ||
} | ||
volumeMount := v1.VolumeMount{ | ||
MountPath: GCSCredentialVolumeMountPath, | ||
Name: GCSCredentialVolumeName, | ||
ReadOnly: true, | ||
} | ||
return volume, volumeMount | ||
} |
68 changes: 68 additions & 0 deletions
68
pkg/reconciler/ksvc/resources/credentials/gcs/gcs_secret_test.go
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,68 @@ | ||
/* | ||
Copyright 2019 kubeflow.org. | ||
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 | ||
http://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 gcs | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
func TestGcsSecret(t *testing.T) { | ||
scenarios := map[string]struct { | ||
secret *v1.Secret | ||
expectedVolume v1.Volume | ||
expectedVolumeMount v1.VolumeMount | ||
}{ | ||
"GCSSecretVolume": { | ||
secret: &v1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "user-gcp-sa", | ||
}, | ||
Data: map[string][]byte{ | ||
GCSCredentialFileName: {}, | ||
}, | ||
}, | ||
expectedVolumeMount: v1.VolumeMount{ | ||
Name: GCSCredentialVolumeName, | ||
ReadOnly: true, | ||
MountPath: GCSCredentialVolumeMountPath, | ||
}, | ||
expectedVolume: v1.Volume{ | ||
Name: GCSCredentialVolumeName, | ||
VolumeSource: v1.VolumeSource{ | ||
Secret: &v1.SecretVolumeSource{ | ||
SecretName: "user-gcp-sa", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, scenario := range scenarios { | ||
volume, volumeMount := BuildSecretVolume(scenario.secret) | ||
|
||
if diff := cmp.Diff(scenario.expectedVolume, volume); diff != "" { | ||
t.Errorf("Test %q unexpected volume (-want +got): %v", name, diff) | ||
} | ||
|
||
if diff := cmp.Diff(scenario.expectedVolumeMount, volumeMount); diff != "" { | ||
t.Errorf("Test %q unexpected volumeMount (-want +got): %v", name, diff) | ||
} | ||
} | ||
} |
Oops, something went wrong.