Skip to content

Commit

Permalink
fixed bug with lifecycle reading incorrect PreStop
Browse files Browse the repository at this point in the history
  • Loading branch information
NimbleArchitect committed Sep 16, 2022
1 parent 82a0d4b commit 816282d
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.19
- name: GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
Expand Down
77 changes: 77 additions & 0 deletions pkg/plugin/builder-template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// package plugin

// import (
// v1 "k8s.io/api/core/v1"
// )

// func Template (cmd *cobra.Command, kubeFlags *genericclioptions.ConfigFlags, args []string) error {

// log := logger{location: "Template"}
// log.Debug("Start")

// loopinfo := commands{}
// builder := RowBuilder{}
// builder.LoopSpec = true
// builder.ShowInitContainers = true
// builder.PodName = args

// connect := Connector{}
// if err := connect.LoadConfig(kubeFlags); err != nil {
// return err
// }

// commonFlagList, err := processCommonFlags(cmd)
// if err != nil {
// return err
// }
// connect.Flags = commonFlagList
// builder.Connection = &connect
// builder.SetFlagsFrom(commonFlagList)

// table := Table{}
// builder.Table = &table
// builder.ShowTreeView = commonFlagList.showTreeView

// builder.Build(loopinfo)

// if err := table.SortByNames(commonFlagList.sortList...); err != nil {
// return err
// }

// outputTableAs(table, commonFlagList.outputAs)
// return nil

// }

// type template struct {
// }

// func (s template) Headers() []string {
// return []string{
// // "USED", "REQUEST", "LIMIT", "%REQ", "%LIMIT",
// }
// }

// func (s template) BuildContainerStatus(container v1.ContainerStatus, info BuilderInformation) ([][]Cell, error) {
// return [][]Cell{}, nil
// }

// func (s template) BuildEphemeralContainerStatus(container v1.ContainerStatus, info BuilderInformation) ([][]Cell, error) {
// return [][]Cell{}, nil
// }

// func (s template) HideColumns(info BuilderInformation) []int {
// return []int{}
// }

// func (s template) BuildContainerSpec(container v1.Container, info BuilderInformation) ([][]Cell, error) {
// out := [][]Cell{}
// // out[0] = commandsBuildRow(cmdLine, info)
// return out, nil
// }

// func (s template) BuildEphemeralContainerSpec(container v1.EphemeralContainer, info BuilderInformation) ([][]Cell, error) {
// out := [][]Cell{}
// // out[0] = commandsBuildRow(cmdLine, info)
// return out, nil
// }
9 changes: 6 additions & 3 deletions pkg/plugin/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ func (b *RowBuilder) Build(loop Looper) error {
}

// walkTreeCreateRow - recursive function to loop over each child item along with all sub children, buildPodTree
// is called on each child with the results passed to Sum so we can calculate parent values from the children
//
// is called on each child with the results passed to Sum so we can calculate parent values from the children
func (b *RowBuilder) walkTreeCreateRow(loop Looper, info *BuilderInformation, parent LeafNode) ([][]Cell, error) {
var totals [][]Cell
log := logger{location: "RowBuilder:walkTreeCreateRow"}
Expand Down Expand Up @@ -565,7 +566,8 @@ func (b *RowBuilder) setVisibleColumns(info *BuilderInformation) {
}

// PodLoop given a pod we loop over all containers adding to the table as we go
// returns a copy of rows added and nil on success
//
// returns a copy of rows added and nil on success
func (b *RowBuilder) podLoop(loop Looper, info BuilderInformation, pod v1.Pod, indentLevel int) ([][]Cell, error) {
var podRowsOut [][]Cell

Expand Down Expand Up @@ -731,7 +733,8 @@ func (b *RowBuilder) podLoop(loop Looper, info BuilderInformation, pod v1.Pod, i
}

// makeFullRow adds the listed columns to the default columns, outputs
// the complete row as a list of columns
//
// the complete row as a list of columns
func (b *RowBuilder) makeFullRow(info *BuilderInformation, indentLevel int, columns ...[]Cell) []Cell {
log := logger{location: "RowBuilder:makeFullRow"}
log.Debug("Start")
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *lifecycle) buildLifecycleList(lifecycle *v1.Lifecycle) map[string]lifec
}

if lifecycle.PreStop != nil {
lifeCycleList["preStop"] = s.buildLifecycleAction(lifecycle.PostStart)
lifeCycleList["preStop"] = s.buildLifecycleAction(lifecycle.PreStop)
}

return lifeCycleList
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugin/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type logger struct {
}

// given log number (int) return the prefix string (ERROR,INFO,DEBUG,etc) and a colour map
// that can be used with fmt.Printf and friends
//
// that can be used with fmt.Printf and friends
func logGetType(logType int) (string, string) {

// Black: [30m
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ func splitAndFilterList(rawSortString string, filterString string) ([]string, er
}

// splitAndFilterMatchList removes any chars not in filterList and splits the line based on values in []operator, returns a map[string]matchValue type.
// the order of operatorList is important as the match is done on a first come first served basis
//
// the order of operatorList is important as the match is done on a first come first served basis
func splitAndFilterMatchList(rawSortString string, filterString string, operatorList []string) (map[string]matchValue, error) {
// based on a whitelist approach sort just removes invalid chars,
// we cant check header names as we dont know them at this point
Expand Down
6 changes: 4 additions & 2 deletions pkg/plugin/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ func (t *Table) PrintCsv() {
}

// sort Sorts via the column number, uses the full column count including hidden columns
// function can be run multiple times and is cumalitive
//
// function can be run multiple times and is cumalitive
func (t *Table) sort(list []int, columnNumber int, ascending bool) {
// rather then reordering all rows we have an order array that we can loop through
// sort contains the actual row number to use next
Expand Down Expand Up @@ -547,7 +548,8 @@ func NewCellText(text string) Cell {
}

// NewCellTextIndent creates a text cell with an indentation indicator, this dosen't actually indent the cell it just
// tells table.go Print to indent it for us
//
// tells table.go Print to indent it for us
func NewCellTextIndent(text string, indentLevel int) Cell {

temp := strings.Replace(text, "\r", "\\r", -1)
Expand Down
24 changes: 12 additions & 12 deletions pkg/plugin/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

var table Table

//*****************
//SetHeader
//*****************
// *****************
// SetHeader
// *****************
type tableSetHeaderTest struct {
arg1 []string
count int
Expand Down Expand Up @@ -39,9 +39,9 @@ func TestTableSetHeader(t *testing.T) {

}

//*****************
//AddRow
//*****************
// *****************
// AddRow
// *****************
type addRowTest struct {
arg1 []Cell
rowCount int
Expand Down Expand Up @@ -75,9 +75,9 @@ func TestAddRow(t *testing.T) {

}

//*****************
//Order
//*****************
// *****************
// Order
// *****************
type orderTest struct {
arg1 []int
expected []int
Expand All @@ -103,9 +103,9 @@ func TestOrder(t *testing.T) {

}

//*****************
//HideColumn
//*****************
// *****************
// HideColumn
// *****************
type hideColumnTest struct {
arg1 int
expected []headerRow
Expand Down
30 changes: 15 additions & 15 deletions pkg/plugin/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

//*****************
//skipContainerName
//*****************
// *****************
// skipContainerName
// *****************
type skipContainerNameTest struct {
arg1 commonFlags
arg2 string
Expand All @@ -33,9 +33,9 @@ func TestSkipContainerName(t *testing.T) {

}

//********************
//skipmemoryGetUnitLst
//********************
// ********************
// skipmemoryGetUnitLst
// ********************
type skipMemoryGetUnitLstTest struct {
arg1 string
expected1 int64
Expand Down Expand Up @@ -95,9 +95,9 @@ func TestMemoryGetUnitLst(t *testing.T) {

}

//*******************
//memoryHumanReadable
//*******************
// *******************
// memoryHumanReadable
// *******************
type memoryHumanReadableTest struct {
arg1 int64
arg2 string
Expand Down Expand Up @@ -128,9 +128,9 @@ func TestMemoryHumanReadable(t *testing.T) {
}
}

//*******************
//validateFloat64
//*******************
// *******************
// validateFloat64
// *******************
func TestValidateFloat64(t *testing.T) {
input := 1234.1234
output := validateFloat64(input)
Expand All @@ -145,9 +145,9 @@ func TestValidateFloat64(t *testing.T) {
}
}

//*******************
//portAsString
//*******************
// *******************
// portAsString
// *******************
type portAsStringTest struct {
arg1 intstr.IntOrString
expected string
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugin/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var versionsShort = "Display container versions and mount points"

var helpTemplate = `
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}
More information at: https://nimblearchitect.github.io/kubectl-ice/
More information, documentation and examples at: https://nimblearchitect.github.io/kubectl-ice/
find this program useful? Please consider a donation: https://nimblearchitect.github.io/kubectl-ice/donations/
`

Expand Down

0 comments on commit 816282d

Please sign in to comment.