Ejemplo n.º 1
0
func setupRun(cmd *cobra.Command, args []string) {
	fsClient, err := fs.NewFsClient()
	if err != nil {
		ExitStderr(mask(err))
	}

	systemdClient, err := systemd.NewSystemdClient()
	if err != nil {
		ExitStderr(mask(err))
	}

	var fetchClient fetchclient.FetchClient
	if awsAccessKey == "" || awsSecretKey == "" {
		fetchClient, err = httpclient.NewHTTPClient(httpEndpoint)
		if err != nil {
			ExitStderr(mask(err))
		}
	} else {
		fetchClient, err = s3.NewS3Client(awsAccessKey, awsSecretKey, s3Endpoint, s3Bucket)
		if err != nil {
			ExitStderr(mask(err))
		}
	}

	// distribution service
	if execute(globalFlags.steps, "distribution") {
		if err := distribution.Teardown(fsClient, distributionPath); err != nil {
			ExitStderr(mask(err))
		}

		if err := distribution.Setup(fsClient, distributionPath); err != nil {
			ExitStderr(mask(err))
		}
	}

	// overlay mount service
	useOverlay := execute(globalFlags.steps, "overlay")
	if useOverlay {
		if err := overlay.Teardown(fsClient, systemdClient, distributionPath, overlayWorkdir, overlayMountPoint); err != nil {
			ExitStderr(mask(err))
		}

		if err := overlay.Setup(fsClient, systemdClient, distributionPath, overlayWorkdir, overlayMountPoint); err != nil {
			ExitStderr(mask(err))
		}
	}

	// iptables
	useIPTables := execute(globalFlags.steps, "iptables")
	if useIPTables {
		if err := iptables.Teardown(fsClient, systemdClient); err != nil {
			ExitStderr(mask(err))
		}

		if err := iptables.Setup(fsClient, systemdClient, subnet, dockerSubnet, gateway, useDockerIptableRules); err != nil {
			ExitStderr(mask(err))
		}
	}

	// ip6tables
	useIP6Tables := execute(globalFlags.steps, "ip6tables")
	if useIP6Tables {
		if err := ip6tables.Teardown(fsClient, systemdClient); err != nil {
			ExitStderr(mask(err))
		}

		if err := ip6tables.Setup(fsClient, systemdClient); err != nil {
			ExitStderr(mask(err))
		}
	}

	// docker service
	if execute(globalFlags.steps, "docker") {
		if err := docker.Teardown(fsClient, systemdClient, stopDaemons); err != nil {
			ExitStderr(mask(err))
		}

		// !useIPTables is used, because when the iptables step is enabled, we want
		// --iptables=false for the docker daemon.
		if err := docker.Setup(fsClient, systemdClient, fetchClient, overlayMountPoint, dockerVersion, privateRegistry, !useDockerIptableRules, startDaemons, useOverlay); err != nil {
			ExitStderr(mask(err))
		}
	}

	// fleet service
	if execute(globalFlags.steps, "fleet") {
		if err := fleet.Teardown(fsClient, systemdClient, overlayMountPoint, stopDaemons); err != nil {
			ExitStderr(mask(err))
		}

		if err := fleet.Setup(fsClient, systemdClient, fetchClient, overlayMountPoint, fleetVersion, startDaemons, useOverlay); err != nil {
			ExitStderr(mask(err))
		}
	}

	// etcd service
	if execute(globalFlags.steps, "etcd") {
		if err := etcd.Teardown(fsClient, systemdClient, overlayMountPoint, stopDaemons); err != nil {
			ExitStderr(mask(err))
		}

		if err := etcd.Setup(fsClient, systemdClient, fetchClient, overlayMountPoint, etcdVersion, startDaemons, useOverlay); err != nil {
			ExitStderr(mask(err))
		}
	}

	// rkt binary
	if execute(globalFlags.steps, "rkt") {
		if err := rkt.Teardown(fsClient, systemdClient, overlayMountPoint, stopDaemons); err != nil {
			ExitStderr(mask(err))
		}

		if err := rkt.Setup(fsClient, systemdClient, fetchClient, overlayMountPoint, rktVersion, startDaemons, useOverlay); err != nil {
			ExitStderr(mask(err))
		}
	}

	// k8s binaries
	if execute(globalFlags.steps, "k8s") {
		if err := k8s.Teardown(fsClient, overlayMountPoint); err != nil {
			ExitStderr(mask(err))
		}

		if err := k8s.Setup(fsClient, fetchClient, overlayMountPoint, k8sVersion); err != nil {
			ExitStderr(mask(err))
		}
	}
}
Ejemplo n.º 2
0
func teardownRun(cmd *cobra.Command, args []string) {
	fs, err := fsPkg.NewFsClient()
	if err != nil {
		ExitStderr(err)
	}

	systemd, err := systemdPkg.NewSystemdClient()
	if err != nil {
		ExitStderr(err)
	}

	// iptables
	if execute(globalFlags.steps, "iptables") {
		if err := iptablesPkg.Teardown(fs, systemd); err != nil {
			ExitStderr(err)
		}
	}

	// ip6tables
	if execute(globalFlags.steps, "ip6tables") {
		if err := ip6tablesPkg.Teardown(fs, systemd); err != nil {
			ExitStderr(err)
		}
	}

	// k8s binaries
	if execute(globalFlags.steps, "k8s") {
		if err := k8sPkg.Teardown(fs, overlayMountPoint); err != nil {
			ExitStderr(err)
		}
	}

	// rkt binaries
	if execute(globalFlags.steps, "rkt") {
		if err := rktPkg.Teardown(fs, systemd, overlayMountPoint, stopDaemons); err != nil {
			ExitStderr(err)
		}
	}

	// docker service
	if execute(globalFlags.steps, "docker") {
		if err := dockerPkg.Teardown(fs, systemd, stopDaemons); err != nil {
			ExitStderr(err)
		}
	}

	// fleet service
	if execute(globalFlags.steps, "fleet") {
		if err := fleetPkg.Teardown(fs, systemd, overlayMountPoint, stopDaemons); err != nil {
			ExitStderr(err)
		}
	}

	// etcd service
	if execute(globalFlags.steps, "etcd") {
		if err := etcdPkg.Teardown(fs, systemd, overlayMountPoint, stopDaemons); err != nil {
			ExitStderr(err)
		}
	}

	// overlay service
	if execute(globalFlags.steps, "overlay") {
		if err := overlay.Teardown(fs, systemd, distributionPath, overlayWorkdir, overlayMountPoint); err != nil {
			ExitStderr(err)
		}
	}

	// distribution service
	if execute(globalFlags.steps, "distribution") {
		if err := distribution.Teardown(fs, distributionPath); err != nil {
			ExitStderr(err)
		}
	}
}