func ListBuildBinaries()

in pkg/release/workspace.go [155:258]


func ListBuildBinaries(gitroot, version string) (list []struct{ Path, Platform, Arch string }, err error) {
	list = []struct {
		Path     string
		Platform string
		Arch     string
	}{}
	buildDir := filepath.Join(
		gitroot, fmt.Sprintf("%s-%s", BuildDir, version),
	)

	rootPath := filepath.Join(buildDir, ReleaseStagePath)
	platformsPath := filepath.Join(rootPath, "client")
	if !util.Exists(platformsPath) {
		logrus.Infof("Not adding binaries as %s was not found", platformsPath)
		return list, nil
	}
	platformsAndArches, err := os.ReadDir(platformsPath)
	if err != nil {
		return nil, errors.Wrapf(err, "retrieve platforms from %s", platformsPath)
	}

	for _, platformArch := range platformsAndArches {
		if !platformArch.IsDir() {
			logrus.Warnf(
				"Skipping platform and arch %q because it's not a directory",
				platformArch.Name(),
			)
			continue
		}

		split := strings.Split(platformArch.Name(), "-")
		if len(split) != 2 {
			return nil, errors.Errorf(
				"expected `platform-arch` format for %s", platformArch.Name(),
			)
		}

		platform := split[0]
		arch := split[1]

		src := filepath.Join(
			rootPath, "client", platformArch.Name(), "kubernetes", "client", "bin",
		)

		// We assume here the "server package" is a superset of the "client
		// package"
		serverSrc := filepath.Join(rootPath, "server", platformArch.Name())
		if util.Exists(serverSrc) {
			src = filepath.Join(serverSrc, "kubernetes", "server", "bin")
		}

		if err := filepath.Walk(src,
			func(path string, info os.FileInfo, err error) error {
				if err != nil {
					return err
				}
				if info.IsDir() {
					return nil
				}

				// The binaries directory stores the image tarfiles and the
				// docker tag files. Skip those from the binaries list
				if strings.HasSuffix(path, ".docker_tag") || strings.HasSuffix(path, ".tar") {
					return nil
				}

				list = append(list, struct {
					Path     string
					Platform string
					Arch     string
				}{path, platform, arch})
				return nil
			},
		); err != nil {
			return nil, errors.Wrapf(err, "gathering binaries from %s", src)
		}

		// Copy node binaries if they exist and this isn't a 'server' platform
		nodeSrc := filepath.Join(rootPath, "node", platformArch.Name())
		if !util.Exists(serverSrc) && util.Exists(nodeSrc) {
			src = filepath.Join(nodeSrc, "kubernetes", "node", "bin")
			if err := filepath.Walk(src,
				func(path string, info os.FileInfo, err error) error {
					if err != nil {
						return err
					}
					if info.IsDir() {
						return nil
					}

					list = append(list, struct {
						Path     string
						Platform string
						Arch     string
					}{path, platform, arch})
					return nil
				},
			); err != nil {
				return nil, errors.Wrapf(err, "gathering node binaries from %s", src)
			}
		}
	}
	return list, nil
}