Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update-kind-example-to-containerd_1.5 #1483

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions cli/pkg/kctrl/cmd/package/installed/create_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,12 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
if err != nil {
return err
}
err = o.waitForAppPause(kcClient)
if err != nil {
return err

if o.WaitFlags.Enabled {
err = o.waitForAppPause(kcClient)
if err != nil {
return err
}
}
reconciliationPaused = true

Expand Down
18 changes: 18 additions & 0 deletions cli/pkg/kctrl/cmd/package/installed/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
cmdcore "github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/cmd/core"
"github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/logger"
kcpkgv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -22,6 +23,7 @@ type ListOptions struct {

NamespaceFlags cmdcore.NamespaceFlags
AllNamespaces bool
Wide bool

pkgCmdTreeOpts cmdcore.PackageCommandTreeOpts
}
Expand Down Expand Up @@ -49,6 +51,8 @@ func NewListCmd(o *ListOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
}
o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
cmd.Flags().BoolVarP(&o.AllNamespaces, "all-namespaces", "A", false, "List installed packages in all namespaces")

cmd.Flags().BoolVar(&o.Wide, "wide", false, "show additional info")
return cmd
}

Expand All @@ -74,6 +78,9 @@ func (o *ListOptions) Run() error {
return err
}

messageHeader := uitable.NewHeader("Message")
messageHeader.Hidden = !o.Wide

table := uitable.Table{
Title: tableTitle,

Expand All @@ -83,6 +90,7 @@ func (o *ListOptions) Run() error {
uitable.NewHeader("Package Name"),
uitable.NewHeader("Package Version"),
uitable.NewHeader("Status"),
messageHeader,
},

SortBy: []uitable.ColumnSort{
Expand All @@ -99,10 +107,20 @@ func (o *ListOptions) Run() error {
uitable.NewValueString(pkgi.Spec.PackageRef.RefName),
uitable.NewValueString(pkgi.Status.Version),
uitable.ValueFmt{V: uitable.NewValueString(status), Error: isFailing},
cmdcore.NewValueTruncated(uitable.NewValueString(o.getPkgiStatusMessage(&pkgi)), 50),
})
}

o.ui.PrintTable(table)

return nil
}

func (o *ListOptions) getPkgiStatusMessage(pkgi *kcpkgv1alpha1.PackageInstall) string {
conditionsLen := len(pkgi.Status.Conditions)
if conditionsLen == 0 {
return ""
}
lastCondition := pkgi.Status.Conditions[conditionsLen-1]
return lastCondition.Message
}
14 changes: 11 additions & 3 deletions cli/pkg/kctrl/cmd/package/installed/pause_or_kick.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func NewPauseCmd(o *PauseOrKickOptions, flagsFactory cmdcore.FlagsFactory) *cobr
cmd.Use = "pause INSTALLED_PACKAGE_NAME"
}

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: true,
DefaultInterval: 2 * time.Second,
DefaultTimeout: 5 * time.Minute,
})

return cmd
}

Expand Down Expand Up @@ -165,9 +171,11 @@ func (o *PauseOrKickOptions) Kick(args []string) error {
return err
}

err = o.waitForAppPause(client)
if err != nil {
return err
if o.WaitFlags.Enabled {
err = o.waitForAppPause(client)
if err != nil {
return err
}
}

err = o.unpause(client)
Expand Down
46 changes: 46 additions & 0 deletions cli/test/e2e/package_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ key2: value2
require.Exactly(t, expectedOutputRows, output.Tables[0].Rows)
})

logger.Section("package installed list with one package installed with wide option", func() {
out, err := kappCtrl.RunWithOpts([]string{"package", "installed", "list", "--wide", "--json"}, RunOpts{})
require.NoError(t, err)

output := uitest.JSONUIFromBytes(t, []byte(out))

expectedOutputRows := []map[string]string{{
"message": "",
"name": "testpkgi",
"package_name": "test-pkg.carvel.dev",
"package_version": "1.0.0",
"status": "Reconcile succeeded",
}}
require.Exactly(t, expectedOutputRows, output.Tables[0].Rows)
})

logger.Section("package installed get", func() {

out, err := kappCtrl.RunWithOpts([]string{"package", "installed", "get", "--package-install", pkgiName, "--json"}, RunOpts{})
Expand Down Expand Up @@ -260,6 +276,36 @@ key2: value2
require.Contains(t, err.Error(), "not found")
})

logger.Section("Listing with error in package install", func() {
incorrectValuesFile := `
key1: value1:
`
_, err := kappCtrl.RunWithOpts([]string{"package", "installed", "create", "--package-install", pkgiName,
"-p", packageMetadataName, "--version", packageVersion1,
"--values-file", "-"}, RunOpts{
StdinReader: strings.NewReader(incorrectValuesFile),
AllowError: true,
})
require.Error(t, err)

out, err := kappCtrl.RunWithOpts([]string{"package", "installed", "list", "--wide", "--json"}, RunOpts{})
require.NoError(t, err)

output := uitest.JSONUIFromBytes(t, []byte(out))

expectedOutputRows := []map[string]string{{
"message": "Error (see .status.usefulErrorMessage for details)",
"name": "testpkgi",
"package_name": "test-pkg.carvel.dev",
"package_version": "1.0.0",
"status": "Reconcile failed",
}}
require.Exactly(t, expectedOutputRows, output.Tables[0].Rows)

_, err = kappCtrl.RunWithOpts([]string{"package", "installed", "delete", "--package-install", pkgiName}, RunOpts{})
require.NoError(t, err)
})

logger.Section("package installed update with missing old version", func() {
kappCtrl.RunWithOpts([]string{"package", "installed", "create", "--package-install", pkgiName,
"-p", packageMetadataName, "--version", packageVersion1,
Expand Down
4 changes: 4 additions & 0 deletions config/config/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ spec:
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
- name: kapp-controller-sidecarexec
image: kapp-controller
args: ["--sidecarexec"]
Expand Down Expand Up @@ -89,6 +91,8 @@ spec:
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
volumes:
- name: template-fs
emptyDir:
Expand Down
18 changes: 17 additions & 1 deletion examples/local-kind-environment/scripts/kind-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${reg_name}:${reg_port}"]
endpoint = ["http://${reg_name}:5000"]
EOF

# Add the registry config to the nodes
#
# This is necessary because localhost resolves to loopback addresses that are
# network-namespace local.
# In other words: localhost in the container is not localhost on the host.
#
# We want a consistent name that works from both ends, so we tell containerd to
# alias localhost:${reg_port} to the registry container when pulling images
REGISTRY_DIR="/etc/containerd/certs.d/${reg_name}:${reg_port}"
for node in $(sudo kind get nodes); do
sudo docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
cat <<EOF | sudo docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
[host."http://${reg_name}:${reg_port}"]
EOF
done

# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
Expand Down
Loading