-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a Kubernetes mixin. It updates the design doc a little to reflect a couple of param changes across the three verbs and harmonizes things using camelCase naming per the [style guide](https://google.github.io/styleguide/jsoncstyleguide.xml?showone=Property_Name_Format#Property_Name_Format) from the GOOG. Closes #82
- Loading branch information
1 parent
2aa921d
commit 200a461
Showing
30 changed files
with
1,703 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildBuildCommand(mixin *kubernetes.Mixin) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "build", | ||
Short: "Generate Dockerfile contribution for invocation image", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return mixin.Build() | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildInstallCommand(mixin *kubernetes.Mixin) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "install", | ||
Short: "Use kubectl to apply manifests to cluster", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return mixin.Install() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func main() { | ||
cmd := buildRootCommand(os.Stdin) | ||
if err := cmd.Execute(); err != nil { | ||
fmt.Printf("err: %s\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func buildRootCommand(in io.Reader) *cobra.Command { | ||
mixin := kubernetes.New() | ||
mixin.In = in | ||
cmd := &cobra.Command{ | ||
Use: "kubernetes", | ||
Long: "kuberetes is a porter 👩🏽✈️ mixin that you can you can use to leverage kubernetes manifests", | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
mixin.Out = cmd.OutOrStdout() | ||
mixin.Err = cmd.OutOrStderr() | ||
}, | ||
} | ||
|
||
cmd.PersistentFlags().BoolVar(&mixin.Debug, "debug", false, "Enable debug logging") | ||
cmd.AddCommand(buildVersionCommand(mixin)) | ||
cmd.AddCommand(buildBuildCommand(mixin)) | ||
cmd.AddCommand(buildInstallCommand(mixin)) | ||
cmd.AddCommand(buildUpgradeCommand(mixin)) | ||
cmd.AddCommand(buildUnInstallCommand(mixin)) | ||
cmd.AddCommand(buildSchemaCommand(mixin)) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildSchemaCommand(mixin *kubernetes.Mixin) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "schema", | ||
Short: "Print the json schema for the mixin", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return mixin.PrintSchema() | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildUnInstallCommand(mixin *kubernetes.Mixin) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "uninstall", | ||
Short: "Use kubectl to delete manifests from cluster", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return mixin.UnInstall() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildUpgradeCommand(mixin *kubernetes.Mixin) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "Upgrade", | ||
Short: "Use kubectl to apply manifests to cluster", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return mixin.Upgrade() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildVersionCommand(mixin *kubernetes.Mixin) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the mixin verison", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
mixin.PrintVersion() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const kubeVersion = "v1.13.0" | ||
const dockerFileContents = `RUN apt-get update && \ | ||
apt-get install -y apt-transport-https curl && \ | ||
curl -o kubectl https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/kubectl && \ | ||
mv kubectl /usr/local/bin && \ | ||
chmod a+x /usr/local/bin/kubectl | ||
` | ||
|
||
// Build generates the relevant Dockerfile output for this mixin | ||
func (m *Mixin) Build() error { | ||
_, err := fmt.Fprintf(m.Out, dockerFileContents, kubeVersion) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/deislabs/porter/pkg/context" | ||
) | ||
|
||
type TestMixin struct { | ||
*Mixin | ||
TestContext *context.TestContext | ||
} | ||
|
||
func NewTestMixin(t *testing.T) *TestMixin { | ||
c := context.NewTestContext(t) | ||
m := New() | ||
m.Context = c.Context | ||
return &TestMixin{ | ||
Mixin: m, | ||
TestContext: c, | ||
} | ||
} |
Oops, something went wrong.