Skip to content

Commit

Permalink
change the inventory field to pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed Dec 3, 2020
1 parent 1387f08 commit e9daa87
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
15 changes: 3 additions & 12 deletions commands/initcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (io *KptInitOptions) updateKptfile() error {
return err
}
// Finally, set the inventory parameters in the Kptfile and write it.
kf.Inventory = kptfile.Inventory{
kf.Inventory = &kptfile.Inventory{
Namespace: io.namespace,
Name: io.name,
InventoryID: io.inventoryID,
Expand Down Expand Up @@ -160,17 +160,8 @@ func (io *KptInitOptions) validate() error {

// kptfileInventoryEmpty returns true if the Inventory structure
// in the Kptfile is empty; false otherwise.
func kptfileInventoryEmpty(inv kptfile.Inventory) bool {
if len(inv.Name) > 0 {
return false
}
if len(inv.Namespace) > 0 {
return false
}
if len(inv.InventoryID) > 0 {
return false
}
return true
func kptfileInventoryEmpty(inv *kptfile.Inventory) bool {
return inv == nil
}

// NewCmdInit returns the cobra command for the init command.
Expand Down
12 changes: 2 additions & 10 deletions commands/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,8 @@ func TestKptMigrate_updateKptfile(t *testing.T) {
if len(kf.Inventory.InventoryID) == 0 {
t.Errorf("inventory id not set in Kptfile")
}
} else {
if len(kf.Inventory.Namespace) != 0 {
t.Errorf("inventory name not set in Kptfile")
}
if len(kf.Inventory.Name) != 0 {
t.Errorf("inventory name not set in Kptfile")
}
if len(kf.Inventory.InventoryID) != 0 {
t.Errorf("inventory id not set in Kptfile")
}
} else if kf.Inventory != nil {
t.Errorf("inventory shouldn't be set during dryrun")
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/kptfile/pkgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (

// KptFileName is the name of the KptFile
const (
KptFileName = "Kptfile"
KptFileGroup = "kpt.dev"
KptFileVersion = "v1alpha1"
KptFileName = "Kptfile"
KptFileGroup = "kpt.dev"
KptFileVersion = "v1alpha1"
KptFileAPIVersion = KptFileGroup + "/" + KptFileVersion
)

Expand Down Expand Up @@ -57,7 +57,7 @@ type KptFile struct {
Functions Functions `yaml:"functions,omitempty"`

// Parameters for inventory object.
Inventory Inventory `yaml:"inventory,omitempty"`
Inventory *Inventory `yaml:"inventory,omitempty"`
}

// Inventory encapsulates the parameters for the inventory object. All of the
Expand Down
2 changes: 1 addition & 1 deletion pkg/live/rgpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *ResourceGroupPathManifestReader) Read() ([]*unstructured.Unstructured,

// generateInventoryObj returns the ResourceGroupInventory object using the
// passed information.
func generateInventoryObj(inv kptfile.Inventory) (*unstructured.Unstructured, error) {
func generateInventoryObj(inv *kptfile.Inventory) (*unstructured.Unstructured, error) {
// Validate the parameters
name := strings.TrimSpace(inv.Name)
if name == "" {
Expand Down

0 comments on commit e9daa87

Please sign in to comment.