Skip to content

Commit

Permalink
Restructure package layout to add internal package (rancher#1624)
Browse files Browse the repository at this point in the history
* Move codegen into cmd folder
* Split pkgs by command/binary into internal folder
* Update go imports after moving
* Remove cmd/agent/agent, cmd/controller/fleetcontroller packages
* Remove package comments, which indicated the binary the package belongs to
* Move fleetcli's main.go into cmd/
  • Loading branch information
Mario Manno authored Jul 3, 2023
1 parent 2796d3a commit 1f098a2
Show file tree
Hide file tree
Showing 134 changed files with 233 additions and 243 deletions.
6 changes: 3 additions & 3 deletions .github/scripts/check-for-auto-generated-changes.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
set -ue

go run pkg/codegen/cleanup/main.go > /dev/null
go run pkg/codegen/main.go
go run cmd/codegen/cleanup/main.go > /dev/null
go run cmd/codegen/main.go

go run ./pkg/codegen crds ./charts/fleet-crd/templates/crds.yaml > /dev/null
go run ./cmd/codegen crds ./charts/fleet-crd/templates/crds.yaml > /dev/null

if [ -n "$(git status --porcelain)" ]; then
echo "Generated files have either been changed manually or were not updated.\n"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Set up QEMU
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Build Docker Images
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-multicluster-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Build Docker Images
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Get UUID
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fleet-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Build Docker Images
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Set up QEMU
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Build Docker Images
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ jobs:
run: |
export GOARCH=amd64
go build -gcflags='all=-N -l' -o bin/fleetcontroller-linux-amd64 ./cmd/fleetcontroller
go build -gcflags='all=-N -l' -o bin/fleet-linux-amd64
go build -gcflags='all=-N -l' -o bin/fleet-linux-amd64 ./cmd/fleetcli
go build -gcflags='all=-N -l' -o bin/fleetagent-linux-amd64 ./cmd/fleetagent
export GOARCH=arm64
go build -gcflags='all=-N -l' -o bin/fleetcontroller-linux-arm64 ./cmd/fleetcontroller
go build -gcflags='all=-N -l' -o bin/fleet-linux-arm64
go build -gcflags='all=-N -l' -o bin/fleet-linux-arm64 ./cmd/fleetcli
go build -gcflags='all=-N -l' -o bin/fleetagent-linux-arm64 ./cmd/fleetagent
-
id: meta-fleet
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rancher-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: |
go build -o bin/fleetcontroller-linux-$GOARCH ./cmd/fleetcontroller
go build -o "bin/fleet-linux-$GOARCH"
go build -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
-
name: Set up QEMU
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/docs/generate-cli-docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/pkg/errors"

fleetagent "github.com/rancher/fleet/modules/agent/cmds"
fleetcli "github.com/rancher/fleet/modules/cli/cmds"
fleetcontroller "github.com/rancher/fleet/modules/controller/cmds"
fleetagent "github.com/rancher/fleet/internal/cmd/agent"
fleetcli "github.com/rancher/fleet/internal/cmd/cli"
fleetcontroller "github.com/rancher/fleet/internal/cmd/controller"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
Expand Down
6 changes: 3 additions & 3 deletions cmd/fleetagent/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Package main is the entrypoint for the fleet-agent binary. (fleetagent)
// Package main is the entrypoint for the fleet-agent binary.
package main

import (
_ "net/http/pprof"

"github.com/rancher/fleet/modules/agent/cmds"
"github.com/rancher/fleet/internal/cmd/agent"

command "github.com/rancher/wrangler-cli"
)

func main() {
command.Main(cmds.App())
command.Main(agent.App())
}
4 changes: 2 additions & 2 deletions main.go → cmd/fleetcli/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Package main is the entry point for the fleet apply binary. (fleetapply)
// Package main is the entry point for the fleet apply binary.
package main

import (
"github.com/rancher/fleet/modules/cli/cmds"
cmds "github.com/rancher/fleet/internal/cmd/cli"

command "github.com/rancher/wrangler-cli"

Expand Down
4 changes: 2 additions & 2 deletions cmd/fleetcontroller/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Package main provides the entrypoint for the fleet-controller binary (fleetcontroller)
// Package main provides the entrypoint for the fleet-controller binary.
package main

import (
_ "net/http/pprof"

controller "github.com/rancher/fleet/modules/controller/cmds"
"github.com/rancher/fleet/internal/cmd/controller"

command "github.com/rancher/wrangler-cli"
_ "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io"
Expand Down
2 changes: 1 addition & 1 deletion dev/build-fleet
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ go build -gcflags='all=-N -l' -o bin/fleetcontroller-linux-"$GOARCH" ./cmd/fleet
docker build -f package/Dockerfile -t rancher/fleet:dev --build-arg="ARCH=$GOARCH" .

# fleet agent
go build -gcflags='all=-N -l' -o "bin/fleet-linux-$GOARCH"
go build -gcflags='all=-N -l' -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -gcflags='all=-N -l' -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
docker build -f package/Dockerfile.agent -t rancher/fleet-agent:dev --build-arg="ARCH=$GOARCH" .
2 changes: 1 addition & 1 deletion dev/update-agent-k3d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export GOARCH="${GOARCH:-amd64}"
export CGO_ENABLED=0

# fleet agent
go build -gcflags='all=-N -l' -o "bin/fleet-linux-$GOARCH"
go build -gcflags='all=-N -l' -o "bin/fleet-linux-$GOARCH" ./cmd/fleetcli
go build -gcflags='all=-N -l' -o "bin/fleetagent-linux-$GOARCH" ./cmd/fleetagent
docker build -f package/Dockerfile.agent -t rancher/fleet-agent:dev --build-arg="ARCH=$GOARCH" .

Expand Down
6 changes: 3 additions & 3 deletions generate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
//go:generate go run ./pkg/codegen crds ./charts/fleet-crd/templates/crds.yaml
//go:generate go run cmd/codegen/cleanup/main.go
//go:generate go run cmd/codegen/main.go
//go:generate go run ./cmd/codegen crds ./charts/fleet-crd/templates/crds.yaml

package main
10 changes: 5 additions & 5 deletions integrationtests/agent/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/rancher/fleet/integrationtests/utils"
"github.com/rancher/fleet/modules/agent/pkg/controllers/bundledeployment"
"github.com/rancher/fleet/modules/agent/pkg/deployer"
"github.com/rancher/fleet/modules/agent/pkg/trigger"
"github.com/rancher/fleet/internal/cmd/agent/controllers/bundledeployment"
"github.com/rancher/fleet/internal/cmd/agent/deployer"
"github.com/rancher/fleet/internal/cmd/agent/trigger"
"github.com/rancher/fleet/internal/helmdeployer"
"github.com/rancher/fleet/internal/manifest"
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/durations"
"github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io"
fleetgen "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/helmdeployer"
"github.com/rancher/fleet/pkg/manifest"
"github.com/rancher/lasso/pkg/cache"
lassoclient "github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
Expand Down
2 changes: 1 addition & 1 deletion integrationtests/cli/apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/rancher/fleet/integrationtests/cli"
"github.com/rancher/fleet/modules/cli/apply"
"github.com/rancher/fleet/internal/cmd/cli/apply"
)

var _ = Describe("Fleet apply", Ordered, func() {
Expand Down
4 changes: 2 additions & 2 deletions integrationtests/cli/apply/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"testing"

"github.com/rancher/fleet/modules/cli/apply"
"github.com/rancher/fleet/modules/cli/pkg/client"
"github.com/rancher/fleet/internal/client"
"github.com/rancher/fleet/internal/cmd/cli/apply"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion integrationtests/cli/apply/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"github.com/rancher/fleet/integrationtests/cli"
"github.com/rancher/fleet/modules/cli/apply"
"github.com/rancher/fleet/internal/cmd/cli/apply"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"

. "github.com/onsi/ginkgo/v2"
Expand Down
4 changes: 2 additions & 2 deletions integrationtests/cli/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher/fleet/integrationtests/cli"
"github.com/rancher/fleet/modules/cli/apply"
"github.com/rancher/fleet/pkg/bundlereader"
"github.com/rancher/fleet/internal/bundlereader"
"github.com/rancher/fleet/internal/cmd/cli/apply"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions integrationtests/cli/helm/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"testing"

"github.com/rancher/fleet/modules/cli/apply"
"github.com/rancher/fleet/modules/cli/pkg/client"
"github.com/rancher/fleet/internal/client"
"github.com/rancher/fleet/internal/cmd/cli/apply"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
6 changes: 3 additions & 3 deletions integrationtests/controller/bundle/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"time"

"github.com/rancher/fleet/integrationtests/utils"
"github.com/rancher/fleet/pkg/controllers/bundle"
"github.com/rancher/fleet/pkg/target"
"github.com/rancher/fleet/internal/cmd/controller/controllers/bundle"
"github.com/rancher/fleet/internal/cmd/controller/target"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher/fleet/internal/manifest"
"github.com/rancher/fleet/pkg/durations"
"github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io"
"github.com/rancher/fleet/pkg/manifest"
"github.com/rancher/lasso/pkg/cache"
lassoclient "github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"github.com/rancher/fleet/internal/content"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/content"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/downloader"
helmgetter "helm.sh/helm/v3/pkg/getter"
Expand Down
2 changes: 1 addition & 1 deletion pkg/bundlereader/read.go → internal/bundlereader/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"path/filepath"
"strconv"

"github.com/rancher/fleet/internal/fleetyaml"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/fleetyaml"

name1 "github.com/rancher/wrangler/pkg/name"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sort"
"sync"

"github.com/rancher/fleet/modules/cli/pkg/progress"
"github.com/rancher/fleet/internal/bundlereader/progress"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/semaphore"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"path/filepath"
"strings"

"github.com/rancher/fleet/internal/manifest"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/manifest"
)

const (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package bundledeployment deploys bundles, monitors them and cleans up. (fleetagent)
// Package bundledeployment deploys bundles, monitors them and cleans up.
package bundledeployment

import (
Expand All @@ -12,12 +12,12 @@ import (

"github.com/sirupsen/logrus"

"github.com/rancher/fleet/modules/agent/pkg/deployer"
"github.com/rancher/fleet/modules/agent/pkg/trigger"
"github.com/rancher/fleet/internal/cmd/agent/deployer"
"github.com/rancher/fleet/internal/cmd/agent/trigger"
"github.com/rancher/fleet/internal/helmdeployer"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/durations"
fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/helmdeployer"

"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/merr"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package cluster updates the cluster.fleet.cattle.io status in the upstream cluster with the current node status. (fleetagent)
// Package cluster updates the cluster.fleet.cattle.io status in the upstream cluster with the current node status.
package cluster

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package controllers wires and starts the controllers for the agent. (fleetagent)
// Package controllers wires and starts the controllers for the agent.
package controllers

import (
Expand All @@ -10,15 +10,15 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/util/workqueue"

"github.com/rancher/fleet/modules/agent/pkg/controllers/bundledeployment"
"github.com/rancher/fleet/modules/agent/pkg/controllers/cluster"
"github.com/rancher/fleet/modules/agent/pkg/deployer"
"github.com/rancher/fleet/modules/agent/pkg/trigger"
"github.com/rancher/fleet/internal/cmd/agent/controllers/bundledeployment"
"github.com/rancher/fleet/internal/cmd/agent/controllers/cluster"
"github.com/rancher/fleet/internal/cmd/agent/deployer"
"github.com/rancher/fleet/internal/cmd/agent/trigger"
"github.com/rancher/fleet/internal/helmdeployer"
"github.com/rancher/fleet/internal/manifest"
"github.com/rancher/fleet/pkg/durations"
"github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io"
fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/helmdeployer"
"github.com/rancher/fleet/pkg/manifest"

cache2 "github.com/rancher/lasso/pkg/cache"
"github.com/rancher/lasso/pkg/client"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/kubernetes/scheme"

jsonutil "github.com/rancher/fleet/modules/agent/pkg/deployer/internal/json"
"github.com/rancher/fleet/modules/agent/pkg/deployer/internal/kubernetes_vendor/pkg/api/v1/endpoints"
kubescheme "github.com/rancher/fleet/modules/agent/pkg/deployer/internal/scheme"
jsonutil "github.com/rancher/fleet/internal/cmd/agent/deployer/internal/json"
"github.com/rancher/fleet/internal/cmd/agent/deployer/internal/kubernetes_vendor/pkg/api/v1/endpoints"
kubescheme "github.com/rancher/fleet/internal/cmd/agent/deployer/internal/scheme"
)

const couldNotMarshalErrMsg = "Could not unmarshal to object of type %s: %v"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
package diffnormalize

import (
"github.com/rancher/fleet/modules/agent/pkg/deployer/internal/diff"
"github.com/rancher/fleet/modules/agent/pkg/deployer/internal/normalizers"
"github.com/rancher/fleet/modules/agent/pkg/deployer/internal/resource"
"github.com/rancher/fleet/internal/cmd/agent/deployer/internal/diff"
"github.com/rancher/fleet/internal/cmd/agent/deployer/internal/normalizers"
"github.com/rancher/fleet/internal/cmd/agent/deployer/internal/resource"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand Down
Loading

0 comments on commit 1f098a2

Please sign in to comment.