mirror of https://github.com/kubernetes/kops.git
Remove loader support for nodeup tasks not used in models
This commit is contained in:
parent
e6d73b5ba0
commit
4e68ba9a5b
|
@ -97,10 +97,7 @@ func (l *Loader) Build(baseDir vfs.Path) (map[string]fi.Task, error) {
|
||||||
DefaultHandler: ignoreHandler,
|
DefaultHandler: ignoreHandler,
|
||||||
Contexts: map[string]loader.Handler{
|
Contexts: map[string]loader.Handler{
|
||||||
"files": ignoreHandler,
|
"files": ignoreHandler,
|
||||||
"disks": ignoreHandler,
|
|
||||||
"packages": ignoreHandler,
|
"packages": ignoreHandler,
|
||||||
"services": ignoreHandler,
|
|
||||||
"users": ignoreHandler,
|
|
||||||
},
|
},
|
||||||
Tags: l.tags,
|
Tags: l.tags,
|
||||||
}
|
}
|
||||||
|
@ -115,10 +112,7 @@ func (l *Loader) Build(baseDir vfs.Path) (map[string]fi.Task, error) {
|
||||||
DefaultHandler: l.handleFile,
|
DefaultHandler: l.handleFile,
|
||||||
Contexts: map[string]loader.Handler{
|
Contexts: map[string]loader.Handler{
|
||||||
"files": l.handleFile,
|
"files": l.handleFile,
|
||||||
"disks": l.newTaskHandler("disk/", nodetasks.NewMountDiskTask),
|
|
||||||
"packages": l.newTaskHandler("package/", nodetasks.NewPackage),
|
"packages": l.newTaskHandler("package/", nodetasks.NewPackage),
|
||||||
"services": l.newTaskHandler("service/", nodetasks.NewService),
|
|
||||||
"users": l.newTaskHandler("user/", nodetasks.NewUserTask),
|
|
||||||
},
|
},
|
||||||
Tags: l.tags,
|
Tags: l.tags,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ go_library(
|
||||||
"file.go",
|
"file.go",
|
||||||
"group.go",
|
"group.go",
|
||||||
"load_image.go",
|
"load_image.go",
|
||||||
"mount_disk.go",
|
|
||||||
"package.go",
|
"package.go",
|
||||||
"service.go",
|
"service.go",
|
||||||
"update_packages.go",
|
"update_packages.go",
|
||||||
|
@ -29,8 +28,6 @@ go_library(
|
||||||
"//util/pkg/hashing:go_default_library",
|
"//util/pkg/hashing:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
"//vendor/k8s.io/utils/exec:go_default_library",
|
|
||||||
"//vendor/k8s.io/utils/mount:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,9 @@ func TestArchiveDependencies(t *testing.T) {
|
||||||
child fi.Task
|
child fi.Task
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
parent: &MountDiskTask{
|
parent: &File{
|
||||||
Mountpoint: "/",
|
Path: "/var",
|
||||||
|
Type: FileType_Directory,
|
||||||
},
|
},
|
||||||
child: &Archive{
|
child: &Archive{
|
||||||
TargetDir: "/var/something",
|
TargetDir: "/var/something",
|
||||||
|
@ -39,8 +40,9 @@ func TestArchiveDependencies(t *testing.T) {
|
||||||
parent: &Archive{
|
parent: &Archive{
|
||||||
TargetDir: "/var/something",
|
TargetDir: "/var/something",
|
||||||
},
|
},
|
||||||
child: &MountDiskTask{
|
child: &File{
|
||||||
Mountpoint: "/var/something/subdir",
|
Path: "/var/something/subdir",
|
||||||
|
Type: FileType_Directory,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,16 +116,6 @@ func TestBindMountDependencies(t *testing.T) {
|
||||||
parent fi.Task
|
parent fi.Task
|
||||||
child fi.Task
|
child fi.Task
|
||||||
}{
|
}{
|
||||||
{
|
|
||||||
parent: &MountDiskTask{
|
|
||||||
Mountpoint: "/",
|
|
||||||
},
|
|
||||||
child: &BindMount{
|
|
||||||
Source: containerizedMounterHome,
|
|
||||||
Mountpoint: containerizedMounterHome,
|
|
||||||
Options: []string{"exec"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
parent: &File{
|
parent: &File{
|
||||||
Path: containerizedMounterHome,
|
Path: containerizedMounterHome,
|
||||||
|
|
|
@ -95,15 +95,6 @@ func (e *File) GetDependencies(tasks map[string]fi.Task) []fi.Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Depend on disk mounts
|
|
||||||
// For simplicity, we just depend on _all_ disk mounts
|
|
||||||
// We could check the mountpath, but that feels excessive...
|
|
||||||
for _, v := range tasks {
|
|
||||||
if _, ok := v.(*MountDiskTask); ok {
|
|
||||||
deps = append(deps, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Requires parent directories to be created
|
// Requires parent directories to be created
|
||||||
deps = append(deps, findCreatesDirParents(e.Path, tasks)...)
|
deps = append(deps, findCreatesDirParents(e.Path, tasks)...)
|
||||||
|
|
||||||
|
|
|
@ -1,171 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2019 The Kubernetes Authors.
|
|
||||||
|
|
||||||
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 nodetasks
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"k8s.io/klog"
|
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
|
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
|
||||||
utilexec "k8s.io/utils/exec"
|
|
||||||
"k8s.io/utils/mount"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MountDiskTask is responsible for mounting a device on a mountpoint
|
|
||||||
// It will wait for the device to show up, safe_format_and_mount it,
|
|
||||||
// and then mount it.
|
|
||||||
type MountDiskTask struct {
|
|
||||||
Name string
|
|
||||||
|
|
||||||
Device string `json:"device"`
|
|
||||||
Mountpoint string `json:"mountpoint"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ fi.Task = &MountDiskTask{}
|
|
||||||
|
|
||||||
func (s *MountDiskTask) String() string {
|
|
||||||
return fmt.Sprintf("MountDisk: %s %s->%s", s.Name, s.Device, s.Mountpoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ CreatesDir = &MountDiskTask{}
|
|
||||||
|
|
||||||
// Dir implements CreatesDir::Dir
|
|
||||||
func (e *MountDiskTask) Dir() string {
|
|
||||||
return e.Mountpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ fi.HasDependencies = &MountDiskTask{}
|
|
||||||
|
|
||||||
// GetDependencies implements HasDependencies::GetDependencies
|
|
||||||
func (e *MountDiskTask) GetDependencies(tasks map[string]fi.Task) []fi.Task {
|
|
||||||
var deps []fi.Task
|
|
||||||
|
|
||||||
// Requires parent directories to be created
|
|
||||||
deps = append(deps, findCreatesDirParents(e.Mountpoint, tasks)...)
|
|
||||||
return deps
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMountDiskTask(name string, contents string, meta string) (fi.Task, error) {
|
|
||||||
s := &MountDiskTask{Name: name}
|
|
||||||
|
|
||||||
err := utils.YamlUnmarshal([]byte(contents), s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error parsing json for disk %q: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *MountDiskTask) Find(c *fi.Context) (*MountDiskTask, error) {
|
|
||||||
mounter := mount.New("")
|
|
||||||
|
|
||||||
mps, err := mounter.List()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error finding existing mounts: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If device is a symlink, it will show up by its final name
|
|
||||||
targetDevice, err := filepath.EvalSymlinks(e.Device)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error resolving device symlinks for %q: %v", e.Device, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range mps {
|
|
||||||
mp := &mps[i]
|
|
||||||
if mp.Device == targetDevice {
|
|
||||||
actual := &MountDiskTask{
|
|
||||||
Name: e.Name,
|
|
||||||
Mountpoint: mp.Path,
|
|
||||||
Device: e.Device, // Use our alias, to keep change detection happy
|
|
||||||
}
|
|
||||||
return actual, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *MountDiskTask) Run(c *fi.Context) error {
|
|
||||||
return fi.DefaultDeltaRunMethod(e, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MountDiskTask) CheckChanges(a, e, changes *MountDiskTask) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ *MountDiskTask) RenderLocal(t *local.LocalTarget, a, e, changes *MountDiskTask) error {
|
|
||||||
dirMode := os.FileMode(0755)
|
|
||||||
|
|
||||||
// Create the mountpoint
|
|
||||||
err := os.MkdirAll(e.Mountpoint, dirMode)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error creating mountpoint %q: %v", e.Mountpoint, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the device to show up
|
|
||||||
for {
|
|
||||||
_, err := os.Stat(e.Device)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
return fmt.Errorf("error checking for device %q: %v", e.Device, err)
|
|
||||||
}
|
|
||||||
klog.Infof("Waiting for device %q to be attached", e.Device)
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
|
||||||
klog.Infof("Found device %q", e.Device)
|
|
||||||
|
|
||||||
// Mount the device
|
|
||||||
if changes.Mountpoint != "" {
|
|
||||||
klog.Infof("Mounting device %q on %q", e.Device, e.Mountpoint)
|
|
||||||
|
|
||||||
mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: utilexec.New()}
|
|
||||||
|
|
||||||
fstype := ""
|
|
||||||
options := []string{}
|
|
||||||
|
|
||||||
err := mounter.FormatAndMount(e.Device, e.Mountpoint, fstype, options)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error formatting and mounting disk %q on %q: %v", e.Device, e.Mountpoint, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Should we add to /etc/fstab?
|
|
||||||
// Mount the master PD as early as possible
|
|
||||||
// echo "/dev/xvdb /mnt/master-pd ext4 noatime 0 0" >> /etc/fstab
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ *MountDiskTask) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *MountDiskTask) error {
|
|
||||||
// TODO: Run safe_format_and_mount
|
|
||||||
// Download on aws (or bake into image)
|
|
||||||
// # TODO: Where to get safe_format_and_mount?
|
|
||||||
//mkdir -p /usr/share/google
|
|
||||||
//cd /usr/share/google
|
|
||||||
//download-or-bust "dc96f40fdc9a0815f099a51738587ef5a976f1da" https://raw.githubusercontent.com/GoogleCloudPlatform/compute-image-packages/82b75f314528b90485d5239ab5d5495cc22d775f/google-startup-scripts/usr/share/google/safe_format_and_mount
|
|
||||||
//chmod +x safe_format_and_mount
|
|
||||||
|
|
||||||
return fmt.Errorf("Disk::RenderCloudInit not implemented")
|
|
||||||
}
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package nodetasks
|
package nodetasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -71,7 +70,7 @@ func (p *Service) GetDependencies(tasks map[string]fi.Task) []fi.Task {
|
||||||
// launching a custom Kubernetes build), they all depend on
|
// launching a custom Kubernetes build), they all depend on
|
||||||
// the "docker.service" Service task.
|
// the "docker.service" Service task.
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
case *File, *Package, *UpdatePackages, *UserTask, *GroupTask, *MountDiskTask, *Chattr, *BindMount, *Archive:
|
case *File, *Package, *UpdatePackages, *UserTask, *GroupTask, *Chattr, *BindMount, *Archive:
|
||||||
deps = append(deps, v)
|
deps = append(deps, v)
|
||||||
case *Service, *LoadImageTask:
|
case *Service, *LoadImageTask:
|
||||||
// ignore
|
// ignore
|
||||||
|
@ -87,22 +86,6 @@ func (s *Service) String() string {
|
||||||
return fmt.Sprintf("Service: %s", s.Name)
|
return fmt.Sprintf("Service: %s", s.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(name string, contents string, meta string) (fi.Task, error) {
|
|
||||||
s := &Service{Name: name}
|
|
||||||
s.Definition = fi.String(contents)
|
|
||||||
|
|
||||||
if meta != "" {
|
|
||||||
err := json.Unmarshal([]byte(meta), s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error parsing json for service %q: %v", name, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.InitDefaults()
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) InitDefaults() *Service {
|
func (s *Service) InitDefaults() *Service {
|
||||||
// Default some values to true: Running, SmartRestart, ManageState
|
// Default some values to true: Running, SmartRestart, ManageState
|
||||||
if s.Running == nil {
|
if s.Running == nil {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
|
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserTask is responsible for creating a user, by calling useradd
|
// UserTask is responsible for creating a user, by calling useradd
|
||||||
|
@ -54,17 +53,6 @@ func (f *UserTask) SetName(name string) {
|
||||||
klog.Fatalf("SetName not supported for User task")
|
klog.Fatalf("SetName not supported for User task")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserTask(name string, contents string, meta string) (fi.Task, error) {
|
|
||||||
s := &UserTask{Name: name}
|
|
||||||
|
|
||||||
err := utils.YamlUnmarshal([]byte(contents), s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error parsing json for service %q: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *UserTask) Find(c *fi.Context) (*UserTask, error) {
|
func (e *UserTask) Find(c *fi.Context) (*UserTask, error) {
|
||||||
info, err := fi.LookupUser(e.Name)
|
info, err := fi.LookupUser(e.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue