mirror of https://github.com/knative/client.git
Enable unparam linter and fix issues (#1224)
This commit is contained in:
parent
4f5fbc634d
commit
b099555c78
|
|
@ -8,6 +8,13 @@ linters:
|
||||||
enable:
|
enable:
|
||||||
- errorlint
|
- errorlint
|
||||||
- unconvert
|
- unconvert
|
||||||
|
- unparam
|
||||||
- prealloc
|
- prealloc
|
||||||
disable:
|
disable:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-rules:
|
||||||
|
- path: test # Excludes /test, *_test.go etc.
|
||||||
|
linters:
|
||||||
|
- unparam
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
params, err = appendRevisionNameFilter(params, client, args)
|
params, err = appendRevisionNameFilter(params, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ func appendServiceFilter(lConfig []clientservingv1.ListConfig, client clientserv
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an additional name is given append this as a revision name filter to the given list
|
// If an additional name is given append this as a revision name filter to the given list
|
||||||
func appendRevisionNameFilter(lConfigs []clientservingv1.ListConfig, client clientservingv1.KnServingClient, args []string) ([]clientservingv1.ListConfig, error) {
|
func appendRevisionNameFilter(lConfigs []clientservingv1.ListConfig, args []string) ([]clientservingv1.ListConfig, error) {
|
||||||
|
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
||||||
|
|
||||||
},
|
},
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return preCheck(cmd, args)
|
return preCheck(cmd)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,7 +144,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
|
||||||
return serviceUpdateCommand
|
return serviceUpdateCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func preCheck(cmd *cobra.Command, args []string) error {
|
func preCheck(cmd *cobra.Command) error {
|
||||||
if cmd.Flags().NFlag() == 0 {
|
if cmd.Flags().NFlag() == 0 {
|
||||||
return fmt.Errorf("flag(s) not set\nUsage: %s", cmd.Use)
|
return fmt.Errorf("flag(s) not set\nUsage: %s", cmd.Use)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,22 +43,19 @@ func (vt VolumeSourceType) String() string {
|
||||||
return names[vt]
|
return names[vt]
|
||||||
}
|
}
|
||||||
|
|
||||||
func containerOfPodSpec(spec *corev1.PodSpec) (*corev1.Container, error) {
|
func containerOfPodSpec(spec *corev1.PodSpec) *corev1.Container {
|
||||||
if len(spec.Containers) == 0 {
|
if len(spec.Containers) == 0 {
|
||||||
newContainer := corev1.Container{}
|
newContainer := corev1.Container{}
|
||||||
spec.Containers = append(spec.Containers, newContainer)
|
spec.Containers = append(spec.Containers, newContainer)
|
||||||
}
|
}
|
||||||
return &spec.Containers[0], nil
|
return &spec.Containers[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnvVars gives the configuration all the env var values listed in the given map of
|
// UpdateEnvVars gives the configuration all the env var values listed in the given map of
|
||||||
// vars. Does not touch any environment variables not mentioned, but it can add
|
// vars. Does not touch any environment variables not mentioned, but it can add
|
||||||
// new env vars and change the values of existing ones, then sort by env key name.
|
// new env vars and change the values of existing ones, then sort by env key name.
|
||||||
func UpdateEnvVars(spec *corev1.PodSpec, toUpdate map[string]string, toRemove []string) error {
|
func UpdateEnvVars(spec *corev1.PodSpec, toUpdate map[string]string, toRemove []string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updated := updateEnvVarsFromMap(container.Env, toUpdate)
|
updated := updateEnvVarsFromMap(container.Env, toUpdate)
|
||||||
updated = removeEnvVars(updated, toRemove)
|
updated = removeEnvVars(updated, toRemove)
|
||||||
// Sort by env key name
|
// Sort by env key name
|
||||||
|
|
@ -72,10 +69,7 @@ func UpdateEnvVars(spec *corev1.PodSpec, toUpdate map[string]string, toRemove []
|
||||||
|
|
||||||
// UpdateEnvFrom updates envFrom
|
// UpdateEnvFrom updates envFrom
|
||||||
func UpdateEnvFrom(spec *corev1.PodSpec, toUpdate []string, toRemove []string) error {
|
func UpdateEnvFrom(spec *corev1.PodSpec, toUpdate []string, toRemove []string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
envFrom, err := updateEnvFrom(container.EnvFrom, toUpdate)
|
envFrom, err := updateEnvFrom(container.EnvFrom, toUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -87,12 +81,9 @@ func UpdateEnvFrom(spec *corev1.PodSpec, toUpdate []string, toRemove []string) e
|
||||||
// UpdateVolumeMountsAndVolumes updates the configuration for volume mounts and volumes.
|
// UpdateVolumeMountsAndVolumes updates the configuration for volume mounts and volumes.
|
||||||
func UpdateVolumeMountsAndVolumes(spec *corev1.PodSpec,
|
func UpdateVolumeMountsAndVolumes(spec *corev1.PodSpec,
|
||||||
mountsToUpdate *util.OrderedMap, mountsToRemove []string, volumesToUpdate *util.OrderedMap, volumesToRemove []string) error {
|
mountsToUpdate *util.OrderedMap, mountsToRemove []string, volumesToUpdate *util.OrderedMap, volumesToRemove []string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
volumeSourceInfoByName, mountsToUpdate, err := reviseVolumeInfoAndMountsToUpdate(spec.Volumes, mountsToUpdate, volumesToUpdate)
|
volumeSourceInfoByName, mountsToUpdate, err := reviseVolumeInfoAndMountsToUpdate(mountsToUpdate, volumesToUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -118,43 +109,32 @@ func UpdateVolumeMountsAndVolumes(spec *corev1.PodSpec,
|
||||||
// UpdateImage a given image
|
// UpdateImage a given image
|
||||||
func UpdateImage(spec *corev1.PodSpec, image string) error {
|
func UpdateImage(spec *corev1.PodSpec, image string) error {
|
||||||
// When not setting the image to a digest, add the user image annotation.
|
// When not setting the image to a digest, add the user image annotation.
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
container.Image = image
|
container.Image = image
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContainerCommand updates container with a given argument
|
// UpdateContainerCommand updates container with a given argument
|
||||||
func UpdateContainerCommand(spec *corev1.PodSpec, command string) error {
|
func UpdateContainerCommand(spec *corev1.PodSpec, command string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
container.Command = []string{command}
|
container.Command = []string{command}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContainerArg updates container with a given argument
|
// UpdateContainerArg updates container with a given argument
|
||||||
func UpdateContainerArg(spec *corev1.PodSpec, arg []string) error {
|
func UpdateContainerArg(spec *corev1.PodSpec, arg []string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
container.Args = arg
|
container.Args = arg
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContainerPort updates container with a given name:port
|
// UpdateContainerPort updates container with a given name:port
|
||||||
func UpdateContainerPort(spec *corev1.PodSpec, port string) error {
|
func UpdateContainerPort(spec *corev1.PodSpec, port string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var containerPort int64
|
var containerPort int64
|
||||||
var name string
|
var name string
|
||||||
|
var err error
|
||||||
|
|
||||||
elements := strings.SplitN(port, ":", 2)
|
elements := strings.SplitN(port, ":", 2)
|
||||||
if len(elements) == 2 {
|
if len(elements) == 2 {
|
||||||
|
|
@ -180,10 +160,7 @@ func UpdateContainerPort(spec *corev1.PodSpec, port string) error {
|
||||||
|
|
||||||
// UpdateUser updates container with a given user id
|
// UpdateUser updates container with a given user id
|
||||||
func UpdateUser(spec *corev1.PodSpec, user int64) error {
|
func UpdateUser(spec *corev1.PodSpec, user int64) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
container.SecurityContext = &corev1.SecurityContext{
|
container.SecurityContext = &corev1.SecurityContext{
|
||||||
RunAsUser: &user,
|
RunAsUser: &user,
|
||||||
}
|
}
|
||||||
|
|
@ -192,10 +169,7 @@ func UpdateUser(spec *corev1.PodSpec, user int64) error {
|
||||||
|
|
||||||
// UpdateResources updates container resources for given revision spec
|
// UpdateResources updates container resources for given revision spec
|
||||||
func UpdateResources(spec *corev1.PodSpec, resources corev1.ResourceRequirements, requestsToRemove, limitsToRemove []string) error {
|
func UpdateResources(spec *corev1.PodSpec, resources corev1.ResourceRequirements, requestsToRemove, limitsToRemove []string) error {
|
||||||
container, err := containerOfPodSpec(spec)
|
container := containerOfPodSpec(spec)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if container.Resources.Requests == nil {
|
if container.Resources.Requests == nil {
|
||||||
container.Resources.Requests = corev1.ResourceList{}
|
container.Resources.Requests = corev1.ResourceList{}
|
||||||
|
|
@ -522,8 +496,7 @@ func existsVolumeNameInVolumeMounts(volumeName string, volumeMounts []corev1.Vol
|
||||||
|
|
||||||
// =======================================================================================
|
// =======================================================================================
|
||||||
|
|
||||||
func reviseVolumeInfoAndMountsToUpdate(volumes []corev1.Volume, mountsToUpdate *util.OrderedMap,
|
func reviseVolumeInfoAndMountsToUpdate(mountsToUpdate *util.OrderedMap, volumesToUpdate *util.OrderedMap) (*util.OrderedMap, *util.OrderedMap, error) {
|
||||||
volumesToUpdate *util.OrderedMap) (*util.OrderedMap, *util.OrderedMap, error) {
|
|
||||||
volumeSourceInfoByName := util.NewOrderedMap() //make(map[string]*volumeSourceInfo)
|
volumeSourceInfoByName := util.NewOrderedMap() //make(map[string]*volumeSourceInfo)
|
||||||
mountsToUpdateRevised := util.NewOrderedMap() //make(map[string]string)
|
mountsToUpdateRevised := util.NewOrderedMap() //make(map[string]string)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ func (e ServiceTraffic) isTagPresent(tag string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ServiceTraffic) untagRevision(tag string, serviceName string) bool {
|
func (e ServiceTraffic) untagRevision(tag string) bool {
|
||||||
for i, target := range e {
|
for i, target := range e {
|
||||||
if target.Tag == tag {
|
if target.Tag == tag {
|
||||||
e[i].Tag = ""
|
e[i].Tag = ""
|
||||||
|
|
@ -281,7 +281,7 @@ func Compute(cmd *cobra.Command, targets []servingv1.TrafficTarget,
|
||||||
// First precedence: Untag revisions
|
// First precedence: Untag revisions
|
||||||
var errTagNames []string
|
var errTagNames []string
|
||||||
for _, tag := range trafficFlags.UntagRevisions {
|
for _, tag := range trafficFlags.UntagRevisions {
|
||||||
tagExists := traffic.untagRevision(tag, serviceName)
|
tagExists := traffic.untagRevision(tag)
|
||||||
if !tagExists {
|
if !tagExists {
|
||||||
errTagNames = append(errTagNames, tag)
|
errTagNames = append(errTagNames, tag)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ func printRowsForHandlerEntry(output io.Writer, handler *handlerEntry, obj runti
|
||||||
|
|
||||||
if results[1].IsNil() {
|
if results[1].IsNil() {
|
||||||
rows := results[0].Interface().([]metav1beta1.TableRow)
|
rows := results[0].Interface().([]metav1beta1.TableRow)
|
||||||
printRows(output, rows, options)
|
printRows(output, rows)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return results[1].Interface().(error)
|
return results[1].Interface().(error)
|
||||||
|
|
@ -104,7 +104,7 @@ func printHeader(columnNames []string, w io.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// printRows writes the provided rows to output.
|
// printRows writes the provided rows to output.
|
||||||
func printRows(output io.Writer, rows []metav1beta1.TableRow, options PrintOptions) {
|
func printRows(output io.Writer, rows []metav1beta1.TableRow) {
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
for i, cell := range row.Cells {
|
for i, cell := range row.Cells {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
|
|
|
||||||
|
|
@ -77,14 +77,11 @@ func NewWatcher(watchFunc watchF, c rest.Interface, ns string, resource string,
|
||||||
polling := &pollingWatcher{
|
polling := &pollingWatcher{
|
||||||
c, ns, resource, name, timeout, make(chan bool), make(chan watch.Event), &sync.WaitGroup{},
|
c, ns, resource, name, timeout, make(chan bool), make(chan watch.Event), &sync.WaitGroup{},
|
||||||
newTickerPollInterval(time.Second), nativePoll(c, ns, resource, name)}
|
newTickerPollInterval(time.Second), nativePoll(c, ns, resource, name)}
|
||||||
err = polling.start()
|
polling.start()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return polling, nil
|
return polling, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *pollingWatcher) start() error {
|
func (w *pollingWatcher) start() {
|
||||||
w.wg.Add(1)
|
w.wg.Add(1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -149,7 +146,6 @@ func (w *pollingWatcher) start() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *pollingWatcher) ResultChan() <-chan watch.Event {
|
func (w *pollingWatcher) ResultChan() <-chan watch.Event {
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func (w *waitForReadyConfig) Wait(watcher watch.Interface, name string, options
|
||||||
floatingTimeout := timeout
|
floatingTimeout := timeout
|
||||||
for {
|
for {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
retry, timeoutReached, err := w.waitForReadyCondition(watcher, start, name, floatingTimeout, options.errorWindowWithDefault(), msgCallback)
|
retry, timeoutReached, err := w.waitForReadyCondition(watcher, start, floatingTimeout, options.errorWindowWithDefault(), msgCallback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, time.Since(start)
|
return err, time.Since(start)
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ func (w *waitForReadyConfig) Wait(watcher watch.Interface, name string, options
|
||||||
// An errorWindow can be specified which takes into account of intermediate "false" ready conditions. So before returning
|
// An errorWindow can be specified which takes into account of intermediate "false" ready conditions. So before returning
|
||||||
// an error, this methods waits for the errorWindow duration and if an "True" or "Unknown" event arrives in the meantime
|
// an error, this methods waits for the errorWindow duration and if an "True" or "Unknown" event arrives in the meantime
|
||||||
// for the "Ready" condition, then the method continues to wait.
|
// for the "Ready" condition, then the method continues to wait.
|
||||||
func (w *waitForReadyConfig) waitForReadyCondition(watcher watch.Interface, start time.Time, name string, timeout time.Duration, errorWindow time.Duration, msgCallback MessageCallback) (retry bool, timeoutReached bool, err error) {
|
func (w *waitForReadyConfig) waitForReadyCondition(watcher watch.Interface, start time.Time, timeout time.Duration, errorWindow time.Duration, msgCallback MessageCallback) (retry bool, timeoutReached bool, err error) {
|
||||||
|
|
||||||
// channel used to transport the error that has been received
|
// channel used to transport the error that has been received
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue