Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
- 'mdtogo/**'
- 'scripts/**'
- 'Makefile'
- 'make/**'
- '.golangci.yml'
- 'go.mod'
- 'go.sum'
- '.github/workflows/go.yml'
Expand Down
6 changes: 3 additions & 3 deletions cli/alpha/live/plan/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ func findAndPrintDiff(before, after *unstructured.Unstructured, prefix string, i
}

switch d.Type {
case "LeftAdd":
case DiffTypeLeftAdd:
txt := print.SprintfWithColor(print.RED, "%s-%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Left)))
fmt.Fprint(ioStreams.Out, txt)
case "RightAdd":
case DiffTypeRightAdd:
txt := print.SprintfWithColor(print.GREEN, "%s+%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Right)))
fmt.Fprint(ioStreams.Out, txt)
case "Change":
case DiffTypeChange:
txt1 := print.SprintfWithColor(print.RED, "%s-%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Left)))
fmt.Fprint(ioStreams.Out, txt1)
txt2 := print.SprintfWithColor(print.GREEN, "%s+%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Right)))
Expand Down
21 changes: 14 additions & 7 deletions cli/alpha/live/plan/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ type Diff struct {
Path string
}

// Diff.Type values.
const (
DiffTypeLeftAdd = "LeftAdd"
DiffTypeRightAdd = "RightAdd"
DiffTypeChange = "Change"
)

func diffObjects(b, a *unstructured.Unstructured) ([]Diff, error) {
diffs, err := diffMaps("", b.Object, a.Object)
if err != nil {
Expand All @@ -43,7 +50,7 @@ func diffMaps(prefix string, l, r map[string]any) ([]Diff, error) {

rv, ok := r[k]
if !ok {
diffs = append(diffs, Diff{Type: "LeftAdd", Path: childPrefix, Left: lv, Right: rv})
diffs = append(diffs, Diff{Type: DiffTypeLeftAdd, Path: childPrefix, Left: lv, Right: rv})
continue
}
childDiffs, err := diffValue(childPrefix, lv, rv)
Expand All @@ -58,7 +65,7 @@ func diffMaps(prefix string, l, r map[string]any) ([]Diff, error) {

lv, ok := l[k]
if !ok {
diffs = append(diffs, Diff{Type: "RightAdd", Path: childPrefix, Left: lv, Right: rv})
diffs = append(diffs, Diff{Type: DiffTypeRightAdd, Path: childPrefix, Left: lv, Right: rv})
continue
}
}
Expand All @@ -72,7 +79,7 @@ func diffSlices(prefix string, l, r []any) ([]Diff, error) {
childPrefix := prefix + "." + strconv.Itoa(i)

if len(r) <= i {
diffs = append(diffs, Diff{Type: "LeftAdd", Path: childPrefix, Left: l[i], Right: nil})
diffs = append(diffs, Diff{Type: DiffTypeLeftAdd, Path: childPrefix, Left: l[i], Right: nil})
continue
}
rv := r[i]
Expand All @@ -87,7 +94,7 @@ func diffSlices(prefix string, l, r []any) ([]Diff, error) {
childPrefix := prefix + "." + strconv.Itoa(i)

if len(l) <= i {
diffs = append(diffs, Diff{Type: "RightAdd", Path: childPrefix, Left: nil, Right: rv})
diffs = append(diffs, Diff{Type: DiffTypeRightAdd, Path: childPrefix, Left: nil, Right: rv})
continue
}
}
Expand All @@ -110,20 +117,20 @@ func diffValue(path string, lv, rv any) ([]Diff, error) {
case map[string]any:
rvMap, ok := rv.(map[string]any)
if !ok {
return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil
return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil
}
return diffMaps(path, lv, rvMap)

case []any:
rvSlice, ok := rv.([]any)
if !ok {
return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil
return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil
}
return diffSlices(path, lv, rvSlice)

default:
if !reflect.DeepEqual(lv, rv) {
return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil
return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil
}
return nil, nil
}
Expand Down
14 changes: 10 additions & 4 deletions cli/fn/cmdeval/cmdeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func GetEvalFnRunner(ctx context.Context, parent string) *EvalFnRunner {
r.Command.Flags().StringVarP(&r.FnType, "type", "t", "",
"`mutator` (default) or `validator`. tell the function type for autocompletion and `--save` flag")
_ = r.Command.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"mutator", "validator"}, cobra.ShellCompDirectiveDefault
return []string{fnTypeMutator, fnTypeValidator}, cobra.ShellCompDirectiveDefault
})
r.Command.Flags().BoolVarP(
&r.SaveFn, "save", "s", false,
Expand Down Expand Up @@ -147,6 +147,12 @@ func EvalCommand(ctx context.Context, name string) *cobra.Command {
return GetEvalFnRunner(ctx, name).Command
}

// Function type values accepted by the --type flag.
const (
fnTypeMutator = "mutator"
fnTypeValidator = "validator"
)

// EvalFnRunner contains the run function
type EvalFnRunner struct {
Command *cobra.Command
Expand Down Expand Up @@ -291,9 +297,9 @@ func (r *EvalFnRunner) SaveFnToKptfile() {
}
var usrMsg string
switch r.FnType {
case "mutator":
case fnTypeMutator:
kf.Pipeline.Mutators, usrMsg = r.updateFnList(kf.Pipeline.Mutators)
case "validator":
case fnTypeValidator:
kf.Pipeline.Validators, usrMsg = r.updateFnList(kf.Pipeline.Validators)
}

Expand Down Expand Up @@ -458,7 +464,7 @@ func (r *EvalFnRunner) validateOptionalFlags() error {
if r.FnType == "" {
return fmt.Errorf("--type must be specified if saving functions to Kptfile (--save=true)")
}
if r.FnType != "mutator" && r.FnType != "validator" {
if r.FnType != fnTypeMutator && r.FnType != fnTypeValidator {
return fmt.Errorf("--type must be either `mutator` or `validator`")
}
}
Expand Down
2 changes: 1 addition & 1 deletion make/info.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

GOLANG_VERSION := 1.26.3
GOLANGCI_LINT_VERSION := 2.11.4
GOLANGCI_LINT_VERSION := 2.15.0
SWAGGER_VERSION := v0.33.1

GORELEASER_CONFIG = release/tag/goreleaser.yaml
Expand Down
37 changes: 22 additions & 15 deletions pkg/live/inventoryrg.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const (
applyRGPollInterval = 2 * time.Second
)

// Field names used in constructing unstructured inventory objects.
const (
fieldKind = "kind"
fieldName = "name"
fieldNamespace = "namespace"
)

// ResourceGroupGVK is the group/version/kind of the custom
// resource used to store inventory.
var ResourceGroupGVK = schema.GroupVersionKind{
Expand Down Expand Up @@ -156,19 +163,19 @@ func (icm *InventoryResourceGroup) Load() (object.ObjMetadataSet, error) {
klog.V(4).Infof("loading %d inventory items", len(items))
for _, itemUncast := range items {
item := itemUncast.(map[string]any)
namespace, _, err := unstructured.NestedString(item, "namespace")
namespace, _, err := unstructured.NestedString(item, fieldNamespace)
if err != nil {
return []object.ObjMetadata{}, err
}
name, _, err := unstructured.NestedString(item, "name")
name, _, err := unstructured.NestedString(item, fieldName)
if err != nil {
return []object.ObjMetadata{}, err
}
group, _, err := unstructured.NestedString(item, "group")
if err != nil {
return []object.ObjMetadata{}, err
}
kind, _, err := unstructured.NestedString(item, "kind")
kind, _, err := unstructured.NestedString(item, fieldKind)
if err != nil {
return []object.ObjMetadata{}, err
}
Expand Down Expand Up @@ -213,10 +220,10 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro
for _, objMeta := range icm.objMetas {
klog.V(4).Infof("storing inventory obj refercence: %s/%s", objMeta.Namespace, objMeta.Name)
objs = append(objs, map[string]any{
"group": objMeta.GroupKind.Group,
"kind": objMeta.GroupKind.Kind,
"namespace": objMeta.Namespace,
"name": objMeta.Name,
"group": objMeta.GroupKind.Group,
fieldKind: objMeta.GroupKind.Kind,
fieldNamespace: objMeta.Namespace,
fieldName: objMeta.Name,
})
}
klog.V(4).Infof("Creating list of %d resources status", len(icm.objMetas))
Expand All @@ -226,14 +233,14 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro
if found {
klog.V(4).Infof("storing inventory obj refercence and its status: %s/%s", objMeta.Namespace, objMeta.Name)
objStatus = append(objStatus, map[string]any{
"group": objMeta.GroupKind.Group,
"kind": objMeta.GroupKind.Kind,
"namespace": objMeta.Namespace,
"name": objMeta.Name,
"status": "Unknown",
"strategy": status.Strategy.String(),
"actuation": status.Actuation.String(),
"reconcile": status.Reconcile.String(),
Comment thread
Catalin-Stratulat-Ericsson marked this conversation as resolved.
Resolved
"group": objMeta.GroupKind.Group,
fieldKind: objMeta.GroupKind.Kind,
fieldNamespace: objMeta.Namespace,
fieldName: objMeta.Name,
"status": "Unknown",
"strategy": status.Strategy.String(),
"actuation": status.Actuation.String(),
"reconcile": status.Reconcile.String(),
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/live/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ func validateInventory(inventory kptfilev1.Inventory) error {
var violations errors.Violations
if inventory.Name == "" {
violations = append(violations, errors.Violation{
Field: "name",
Field: fieldName,
Value: inventory.Name,
Type: errors.Missing,
Reason: "\"inventory.name\" must not be empty",
})
}
if inventory.Namespace == "" {
violations = append(violations, errors.Violation{
Field: "namespace",
Field: fieldNamespace,
Value: inventory.Namespace,
Type: errors.Missing,
Reason: "\"inventory.namespace\" must not be empty",
Expand Down Expand Up @@ -345,10 +345,10 @@ func generateInventoryObj(inv kptfilev1.Inventory) *unstructured.Unstructured {
var inventoryObj = &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": groupVersion,
"kind": ResourceGroupGVK.Kind,
fieldKind: ResourceGroupGVK.Kind,
"metadata": map[string]any{
"name": inv.Name,
"namespace": inv.Namespace,
fieldName: inv.Name,
fieldNamespace: inv.Namespace,
"labels": map[string]any{
common.InventoryLabel: inv.InventoryID,
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/go-upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ FORK_OWNER=kptdev ./upgrade.sh all --push --force # ← allowed

```bash
TARGET_GO_VERSION="1.26.9"
TARGET_GOLANGCI_LINT_VERSION="2.12.2"
TARGET_GOLANGCI_LINT_VERSION="2.15.0"
```

### Repository Format
Expand Down
2 changes: 1 addition & 1 deletion scripts/go-upgrade/config.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FORK_OWNER="${FORK_OWNER:-Nordix}"

# --- Target versions ---
TARGET_GO_VERSION="1.26.9"
TARGET_GOLANGCI_LINT_VERSION="2.12.1"
TARGET_GOLANGCI_LINT_VERSION="2.15.0"

# --- Workspace ---
WORKSPACE_DIR="workspace"
Expand Down
Loading