forked from kubevirt/kubevirt
-
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.
When filled, the service account token etc. will be provided to the pod and VM Signed-off-by: Marc Sluiter <[email protected]>
- Loading branch information
Showing
21 changed files
with
455 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* 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. | ||
* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package config | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"kubevirt.io/kubevirt/pkg/api/v1" | ||
) | ||
|
||
// GetServiceAccountDiskPath returns a path to the ServiceAccount iso image | ||
func GetServiceAccountDiskPath() string { | ||
return filepath.Join(ServiceAccountDiskDir, ServiceAccountDiskName) | ||
} | ||
|
||
// CreateServiceAccountDisk creates the ServiceAccount iso disk which is attached to vmis | ||
func CreateServiceAccountDisk(vmi *v1.VirtualMachineInstance) error { | ||
for _, volume := range vmi.Spec.Volumes { | ||
if volume.ServiceAccount != nil { | ||
var filesPath []string | ||
filesPath, err := getFilesLayout(ServiceAccountSourceDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = createIsoConfigImage(GetServiceAccountDiskPath(), filesPath) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
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,70 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* 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. | ||
* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package config | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"kubevirt.io/kubevirt/pkg/api/v1" | ||
) | ||
|
||
var _ = Describe("ServiceAccount", func() { | ||
|
||
BeforeEach(func() { | ||
var err error | ||
|
||
ServiceAccountSourceDir, err = ioutil.TempDir("", "serviceaccount") | ||
Expect(err).NotTo(HaveOccurred()) | ||
os.MkdirAll(ServiceAccountSourceDir, 0755) | ||
os.OpenFile(filepath.Join(ServiceAccountSourceDir, "token"), os.O_RDONLY|os.O_CREATE, 0666) | ||
os.OpenFile(filepath.Join(ServiceAccountSourceDir, "namespace"), os.O_RDONLY|os.O_CREATE, 0666) | ||
|
||
ServiceAccountDiskDir, err = ioutil.TempDir("", "serviceaccount-disk") | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
AfterEach(func() { | ||
os.RemoveAll(ServiceAccountSourceDir) | ||
os.RemoveAll(ServiceAccountDiskDir) | ||
}) | ||
|
||
It("Should create a new service account iso disk", func() { | ||
vmi := v1.NewMinimalVMI("fake-vmi") | ||
vmi.Spec.Volumes = append(vmi.Spec.Volumes, v1.Volume{ | ||
Name: "serviceaccount-volume", | ||
VolumeSource: v1.VolumeSource{ | ||
ServiceAccount: &v1.ServiceAccountVolumeSource{ | ||
ServiceAccountName: "testaccount", | ||
}, | ||
}, | ||
}) | ||
|
||
err := CreateServiceAccountDisk(vmi) | ||
Expect(err).NotTo(HaveOccurred()) | ||
_, err = os.Stat(filepath.Join(ServiceAccountDiskDir, ServiceAccountDiskName)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
}) |
Oops, something went wrong.