Skip to content

Commit

Permalink
Merge pull request crossplane-contrib#706 from displague/stack-annota…
Browse files Browse the repository at this point in the history
…tions

Stack annotations
  • Loading branch information
jbw976 authored Aug 30, 2019
2 parents a33e45b + f34f4d0 commit 603dc1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 26 additions & 9 deletions cmd/crossplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ limitations under the License.
package main

import (
"io"
"os"
"path/filepath"

awsapis "github.com/crossplaneio/crossplane/aws/apis"
azureapis "github.com/crossplaneio/crossplane/azure/apis"
gcpapis "github.com/crossplaneio/crossplane/gcp/apis"

"github.com/spf13/afero"
"gopkg.in/alecthomas/kingpin.v2"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand All @@ -40,6 +42,7 @@ import (
stacksController "github.com/crossplaneio/crossplane/pkg/controller/stacks"
"github.com/crossplaneio/crossplane/pkg/controller/workload"
"github.com/crossplaneio/crossplane/pkg/stacks"
"github.com/crossplaneio/crossplane/pkg/stacks/walker"
)

func main() {
Expand Down Expand Up @@ -72,8 +75,9 @@ func main() {
//
// Users are not expected to run this command themselves, the stack manager itself should
// execute this command.
extUnpackCmd = extCmd.Command("unpack", "Unpack a stack")
extUnpackDir = extUnpackCmd.Flag("content-dir", "The directory that contains the stack contents").Required().String()
extUnpackCmd = extCmd.Command("unpack", "Unpack a stack")
extUnpackDir = extUnpackCmd.Flag("content-dir", "The directory that contains the stack contents").Required().String()
extUnpackOutfile = extUnpackCmd.Flag("outfile", "The file where the YAML Stack record and CRD artifacts will be written").String()
)
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))

Expand All @@ -98,26 +102,34 @@ func main() {
// manager are the stacks controllers
setupWithManagerFunc = stacksControllerSetupWithManager
case extUnpackCmd.FullCommand():
var outFile io.StringWriter
// stack unpack command was called, run the stack unpacking logic
kingpin.FatalIfError(stacks.Unpack(*extUnpackDir), "failed to unpack stacks")
if extUnpackOutfile == nil || *extUnpackOutfile == "" {
outFile = os.Stdout
} else {
openFile, err := os.Create(*extUnpackOutfile)
kingpin.FatalIfError(err, "Cannot create outfile")
defer closeOrError(openFile)
outFile = openFile
}
// TODO(displague) afero.NewBasePathFs could avoid the need to track Base
fs := afero.NewOsFs()
rd := &walker.ResourceDir{Base: *extUnpackDir, Walker: afero.Afero{Fs: fs}}
kingpin.FatalIfError(stacks.Unpack(rd, outFile), "failed to unpack stacks")
return
default:
kingpin.FatalUsage("unknown command %s", cmd)
}

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
kingpin.FatalIfError(err, "Cannot get config")
}
kingpin.FatalIfError(err, "Cannot get config")

log.Info("Sync period", "duration", syncPeriod.String())

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{SyncPeriod: syncPeriod})
if err != nil {
kingpin.FatalIfError(err, "Cannot create manager")
}
kingpin.FatalIfError(err, "Cannot create manager")

log.Info("Adding schemes")

Expand All @@ -139,6 +151,11 @@ func main() {
kingpin.FatalIfError(mgr.Start(signals.SetupSignalHandler()), "Cannot start controller")
}

func closeOrError(c io.Closer) {
err := c.Close()
kingpin.FatalIfError(err, "Cannot close file")
}

func controllerSetupWithManager(mgr manager.Manager) error {
if err := (&defaultclass.Controllers{}).SetupWithManager(mgr); err != nil {
return err
Expand Down

0 comments on commit 603dc1c

Please sign in to comment.