Skip to content
This repository has been archived by the owner on Mar 1, 2020. It is now read-only.

Commit

Permalink
Cleanup (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8uhnf authored and tamalsaha committed Dec 8, 2017
1 parent 8d4959d commit 21636bf
Show file tree
Hide file tree
Showing 325 changed files with 18,307 additions and 26,612 deletions.
28 changes: 20 additions & 8 deletions Gopkg.lock

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

35 changes: 8 additions & 27 deletions dep/cmd/edit.go → cmds/edit.go
@@ -1,19 +1,18 @@
package cmd
package cmds

import (
"github.com/spf13/cobra"
"bytes"
"fmt"
"github.com/spf13/cobra"
"io/ioutil"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/editor"
"log"
"os"
"path/filepath"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/editor"
"io/ioutil"
"bytes"

"github.com/ghodss/yaml"
apps "k8s.io/api/apps/v1beta1"
// "k8s.io/apimachinery/pkg/util/jsonmergepatch"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"github.com/ghodss/yaml"
"strings"
)

Expand All @@ -32,8 +31,8 @@ var (
func NewEditCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "edit (filename)",
Short: "Edit a file.",
Long: "Edit a _vendor file to generate kubectl patch.",
Short: "Edit resource definition",
Long: "Generates patch via edit command",
Run: func(cmd *cobra.Command, args []string) {
err := RunEdit()
if err != nil {
Expand All @@ -48,21 +47,15 @@ func NewEditCommand() *cobra.Command {
return cmd
}

func AddEditFlag(cmd *cobra.Command) {
// cmd.Flags().StringP("file", "f", "888888", "Edit file, provided through the --file flag.")
}

func RunEdit() error {
root, err := os.Getwd()
if err != nil {
log.Fatalln("Error during get root path.", err)
return err
}
path := filepath.Join(root, srcPath)

fileInfo, err = os.Stat(path)
if err != nil {
log.Fatalln("--------------", err)
return err
}

Expand All @@ -76,13 +69,11 @@ func RunEdit() error {

srcJson, err := yaml.YAMLToJSON(srcFile)
if err != nil {
log.Fatalln("Error, while converting source from yaml to json", err)
return err
}

dstJson, err := yaml.YAMLToJSON(edited)
if err != nil {
log.Fatalln("Error, while converting destination from yaml to json", err)
return err
}

Expand All @@ -98,46 +89,36 @@ func GetPatch(src, dst []byte) error {
patch, err = strategicpatch.CreateTwoWayMergePatch(src, dst, apps.Deployment{})
}
if err != nil {
log.Fatalln("Error to generate patch", err)
return err
}
yamlPatch, err := yaml.JSONToYAML(patch)
if err != nil {
log.Fatalln(err)
return err
}

root, err := os.Getwd()
if err != nil {
log.Fatalln("Error during get root path.", err)
return err
}
patchFolderDir := strings.Replace(srcPath, _VendorFolder, PatchFolder, 1)
lstIndexSlash := strings.LastIndex(patchFolderDir, "/")
dstPath := filepath.Join(root, patchFolderDir[0:lstIndexSlash])
fmt.Println("Patch: ", dstPath)

err = os.MkdirAll(dstPath, 0755)
if err != nil {
log.Fatalln("Error to MkdirAll", err)
return err
}
patchFilePath := filepath.Join(dstPath, fileInfo.Name())
_, err = os.Create(patchFilePath)
if err != nil {
log.Fatalln("Error creating patch file.", err)
return err
}

err = ioutil.WriteFile(patchFilePath, yamlPatch, 0755)
if err != nil {
log.Fatalln("Error to writing patch file.", err)
return err
}

// os.Open()

fmt.Println(string(yamlPatch))
return nil
}

Expand Down
24 changes: 12 additions & 12 deletions dep/cmd/dep.go → cmds/pull.go
@@ -1,30 +1,30 @@
package cmd
package cmds

import (
"context"
"fmt"
"github.com/ghodss/yaml"
"github.com/golang/dep/gps"
"github.com/golang/dep/gps/pkgtree"
typ "github.com/kubepack/pack/type"
"github.com/spf13/cobra"
"os"
"go/build"
"path/filepath"
"io/ioutil"
"github.com/ghodss/yaml"
"log"
typ "github.com/kubepack/pack/type"
"github.com/golang/dep/gps/pkgtree"
"github.com/golang/dep/gps"
"os"
"path/filepath"
"strings"
"context"
"time"
"fmt"
)

var (
verboseMode bool
)

func NewDepCommand() *cobra.Command {
func NewPullCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "dep",
Short: "Command for get non go file(especially yaml files).",
Use: "pull",
Short: "Pulls dependent app manifests",
Run: func(cmd *cobra.Command, args []string) {
err := DepRun()
if err != nil {
Expand Down
50 changes: 50 additions & 0 deletions cmds/root.go
@@ -0,0 +1,50 @@
package cmds

import (
"flag"
"log"
"strings"

v "github.com/appscode/go/version"
"github.com/jpillora/go-ogle-analytics"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/appscode/go/analytics"
)

const (
gaTrackingCode = "UA-62096468-20"
)

func NewPackCmd(version string) *cobra.Command {
var (
enableAnalytics = true
)
cmd := &cobra.Command{
Use: "pack [command]",
Short: `Secure Lightweight Kubernetes Package Manager`,
DisableAutoGenTag: true,
PersistentPreRun: func(c *cobra.Command, args []string) {
c.Flags().VisitAll(func(flag *pflag.Flag) {
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
})
if enableAnalytics && gaTrackingCode != "" {
if client, err := ga.NewClient(gaTrackingCode); err == nil {
client.ClientID(analytics.ClientID())
parts := strings.Split(c.CommandPath(), " ")
client.Send(ga.NewEvent(parts[0], strings.Join(parts[1:], "/")).Label(version))
}
}
},
}
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
// ref: https://github.com/kubernetes/kubernetes/issues/17162#issuecomment-225596212
flag.CommandLine.Parse([]string{})
cmd.PersistentFlags().BoolVar(&enableAnalytics, "analytics", enableAnalytics, "Send analytical events to Google Guard")

cmd.AddCommand(NewEditCommand())
cmd.AddCommand(NewPullCommand())
cmd.AddCommand(NewUpCommand())
cmd.AddCommand(v.NewCmdVersion())
return cmd
}
40 changes: 11 additions & 29 deletions dep/cmd/compile.go → cmds/up.go
@@ -1,17 +1,16 @@
package cmd
package cmds

import (
"github.com/spf13/cobra"
"github.com/evanphx/json-patch"
apps "k8s.io/api/apps/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/Masterminds/vcs"
"github.com/evanphx/json-patch"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
"io/ioutil"
"os"
apps "k8s.io/api/apps/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"log"
"os"
"path/filepath"
"fmt"
"strings"
)

Expand All @@ -23,24 +22,16 @@ var (

const CompileDirectory = "_outlook"

func NewCompileCommand() *cobra.Command {
func NewUpCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "compile",
Short: "Compile with patch.",
Use: "up",
Short: "Compiles patches and vendored manifests into final final resource definitions",
Run: func(cmd *cobra.Command, args []string) {
/*compiledYaml, err := CompileWithPatch()
if err != nil {
log.Fatalln(err)
}
// fmt.Println("yaml", string(compiledYaml))
DumpCompiledFile(compiledYaml)*/
rootPath,err := os.Getwd()
rootPath, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}

fmt.Println("Hello rootpath", rootPath)

err = filepath.Walk(filepath.Join(rootPath, PatchFolder), visitPatchAndDump)
if err != nil {
log.Fatalln(err)
Expand All @@ -63,11 +54,8 @@ func visitPatchAndDump(path string, fileInfo os.FileInfo, err error) error {
return err
}

fmt.Println("hello path-----", string(patchByte))

srcFilepath := strings.Replace(path, PatchFolder, _VendorFolder, 1)

fmt.Println("------------------", filepath.Dir(srcFilepath))
if _, err := os.Stat(srcFilepath); err != nil {
return err
}
Expand Down Expand Up @@ -113,7 +101,6 @@ func CompileWithPatch(srcByte, patchByte []byte) ([]byte, error) {
}

func DumpCompiledFile(compiledYaml []byte, outlookPath string) error {
fmt.Println("hello Dump Compiled File------------", outlookPath)
root, err := os.Getwd()
if err != nil {
return err
Expand All @@ -124,8 +111,7 @@ func DumpCompiledFile(compiledYaml []byte, outlookPath string) error {
return err
}


// If not exists mkdir the folder
// If not exists mkdir all the folder
outlookDir := filepath.Dir(outlookPath)
if _, err := os.Stat(outlookDir); err != nil {
if os.IsNotExist(err) {
Expand All @@ -136,8 +122,6 @@ func DumpCompiledFile(compiledYaml []byte, outlookPath string) error {
}
}

// outLookFilePath := filepath.Join(dstPath, patchFileInfo.Name())
fmt.Println("file name-----", outlookPath)
_, err = os.Create(outlookPath)
if err != nil {
return err
Expand Down Expand Up @@ -176,7 +160,5 @@ func getAnnotatedWithCommitHash(yamlByte []byte, dir string) ([]byte, error) {
return nil, err
}

fmt.Println("Hello world---------------After annotated yaml---", string(annotatedYamlByte))

return annotatedYamlByte, nil
}

0 comments on commit 21636bf

Please sign in to comment.