diff --git a/upup/pkg/fi/nodeup/loader.go b/upup/pkg/fi/nodeup/loader.go index 471cc41faf..d1e0508a8f 100644 --- a/upup/pkg/fi/nodeup/loader.go +++ b/upup/pkg/fi/nodeup/loader.go @@ -97,10 +97,7 @@ func (l *Loader) Build(baseDir vfs.Path) (map[string]fi.Task, error) { DefaultHandler: ignoreHandler, Contexts: map[string]loader.Handler{ "files": ignoreHandler, - "disks": ignoreHandler, "packages": ignoreHandler, - "services": ignoreHandler, - "users": ignoreHandler, }, Tags: l.tags, } @@ -115,10 +112,7 @@ func (l *Loader) Build(baseDir vfs.Path) (map[string]fi.Task, error) { DefaultHandler: l.handleFile, Contexts: map[string]loader.Handler{ "files": l.handleFile, - "disks": l.newTaskHandler("disk/", nodetasks.NewMountDiskTask), "packages": l.newTaskHandler("package/", nodetasks.NewPackage), - "services": l.newTaskHandler("service/", nodetasks.NewService), - "users": l.newTaskHandler("user/", nodetasks.NewUserTask), }, Tags: l.tags, } diff --git a/upup/pkg/fi/nodeup/nodetasks/BUILD.bazel b/upup/pkg/fi/nodeup/nodetasks/BUILD.bazel index b6b74ff1c5..de77260dfc 100644 --- a/upup/pkg/fi/nodeup/nodetasks/BUILD.bazel +++ b/upup/pkg/fi/nodeup/nodetasks/BUILD.bazel @@ -11,7 +11,6 @@ go_library( "file.go", "group.go", "load_image.go", - "mount_disk.go", "package.go", "service.go", "update_packages.go", @@ -29,8 +28,6 @@ go_library( "//util/pkg/hashing:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/sets: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", ], ) diff --git a/upup/pkg/fi/nodeup/nodetasks/archive_test.go b/upup/pkg/fi/nodeup/nodetasks/archive_test.go index 2828f9a9e7..d87713af87 100644 --- a/upup/pkg/fi/nodeup/nodetasks/archive_test.go +++ b/upup/pkg/fi/nodeup/nodetasks/archive_test.go @@ -28,8 +28,9 @@ func TestArchiveDependencies(t *testing.T) { child fi.Task }{ { - parent: &MountDiskTask{ - Mountpoint: "/", + parent: &File{ + Path: "/var", + Type: FileType_Directory, }, child: &Archive{ TargetDir: "/var/something", @@ -39,8 +40,9 @@ func TestArchiveDependencies(t *testing.T) { parent: &Archive{ TargetDir: "/var/something", }, - child: &MountDiskTask{ - Mountpoint: "/var/something/subdir", + child: &File{ + Path: "/var/something/subdir", + Type: FileType_Directory, }, }, } diff --git a/upup/pkg/fi/nodeup/nodetasks/bindmount_test.go b/upup/pkg/fi/nodeup/nodetasks/bindmount_test.go index 2a437c053b..b8eb8b2450 100644 --- a/upup/pkg/fi/nodeup/nodetasks/bindmount_test.go +++ b/upup/pkg/fi/nodeup/nodetasks/bindmount_test.go @@ -116,16 +116,6 @@ func TestBindMountDependencies(t *testing.T) { parent fi.Task child fi.Task }{ - { - parent: &MountDiskTask{ - Mountpoint: "/", - }, - child: &BindMount{ - Source: containerizedMounterHome, - Mountpoint: containerizedMounterHome, - Options: []string{"exec"}, - }, - }, { parent: &File{ Path: containerizedMounterHome, diff --git a/upup/pkg/fi/nodeup/nodetasks/file.go b/upup/pkg/fi/nodeup/nodetasks/file.go index b1a14a02d5..c365753cc0 100644 --- a/upup/pkg/fi/nodeup/nodetasks/file.go +++ b/upup/pkg/fi/nodeup/nodetasks/file.go @@ -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 deps = append(deps, findCreatesDirParents(e.Path, tasks)...) diff --git a/upup/pkg/fi/nodeup/nodetasks/mount_disk.go b/upup/pkg/fi/nodeup/nodetasks/mount_disk.go deleted file mode 100644 index 74422f2e27..0000000000 --- a/upup/pkg/fi/nodeup/nodetasks/mount_disk.go +++ /dev/null @@ -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") -} diff --git a/upup/pkg/fi/nodeup/nodetasks/service.go b/upup/pkg/fi/nodeup/nodetasks/service.go index 0e1b838fde..8164951bd2 100644 --- a/upup/pkg/fi/nodeup/nodetasks/service.go +++ b/upup/pkg/fi/nodeup/nodetasks/service.go @@ -17,7 +17,6 @@ limitations under the License. package nodetasks import ( - "encoding/json" "fmt" "io/ioutil" "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 // the "docker.service" Service task. 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) case *Service, *LoadImageTask: // ignore @@ -87,22 +86,6 @@ func (s *Service) String() string { 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 { // Default some values to true: Running, SmartRestart, ManageState if s.Running == nil { diff --git a/upup/pkg/fi/nodeup/nodetasks/user.go b/upup/pkg/fi/nodeup/nodetasks/user.go index 5cec277c85..13268cb763 100644 --- a/upup/pkg/fi/nodeup/nodetasks/user.go +++ b/upup/pkg/fi/nodeup/nodetasks/user.go @@ -26,7 +26,6 @@ import ( "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" ) // 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") } -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) { info, err := fi.LookupUser(e.Name) if err != nil {