diff --git a/go.mod b/go.mod index c52d1978..cf90c210 100644 --- a/go.mod +++ b/go.mod @@ -127,5 +127,3 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) - -replace k8s.io/kubectl => k8s.io/kubectl v0.28.2 diff --git a/go.sum b/go.sum index 36d456fe..f3bd2d2d 100644 --- a/go.sum +++ b/go.sum @@ -869,8 +869,8 @@ k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0= k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo= k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= -k8s.io/kubectl v0.28.2 h1:fOWOtU6S0smdNjG1PB9WFbqEIMlkzU5ahyHkc7ESHgM= -k8s.io/kubectl v0.28.2/go.mod h1:6EQWTPySF1fn7yKoQZHYf9TPwIl2AygHEcJoxFekr64= +k8s.io/kubectl v0.29.0 h1:Oqi48gXjikDhrBF67AYuZRTcJV4lg2l42GmvsP7FmYI= +k8s.io/kubectl v0.29.0/go.mod h1:0jMjGWIcMIQzmUaMgAzhSELv5WtHo2a8pq67DtviAJs= k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/pkg/actuators/machine/machine_scope.go b/pkg/actuators/machine/machine_scope.go index 6bace0a1..7bb7bcb9 100644 --- a/pkg/actuators/machine/machine_scope.go +++ b/pkg/actuators/machine/machine_scope.go @@ -288,26 +288,39 @@ func (s *machineScope) setProviderStatus(vm *nutanixClientV3.VMIntentResponse, c s.providerStatus.VmUUID = vm.Metadata.UUID // update machine.status.addresses - addresses := s.machine.Status.Addresses - addr := getExistingAddress(addresses, corev1.NodeInternalIP) - if addr != nil { - addr.Address = *vm.Status.Resources.NicList[0].IPEndpointList[0].IP - } else { - addresses = append(addresses, corev1.NodeAddress{ - Type: corev1.NodeInternalIP, - Address: *vm.Status.Resources.NicList[0].IPEndpointList[0].IP, - }) + machineAddresses := []corev1.NodeAddress{} + vmIPEndpoints := make(map[string]bool) + + for _, nic := range vm.Status.Resources.NicList { + for _, ipEndpoint := range nic.IPEndpointList { + if ipEndpoint.IP != nil && *ipEndpoint.IP != "" { + vmIPEndpoints[*ipEndpoint.IP] = true + } + } } - addr = getExistingAddress(addresses, corev1.NodeInternalDNS) - if addr != nil { - addr.Address = *vm.Spec.Name - } else { - addresses = append(addresses, corev1.NodeAddress{ - Type: corev1.NodeInternalDNS, - Address: *vm.Spec.Name, + + // add the NodeInternalIP addresses to the Machine object using the vm's vmIPEndpoints + for ip, _ := range vmIPEndpoints { + // add the ip address to the Machine object. + machineAddresses = append(machineAddresses, corev1.NodeAddress{ + Type: corev1.NodeInternalIP, + Address: ip, }) } - s.machine.Status.Addresses = addresses + + // add the NodeInternalDNS and NodeHostName addresses to the Machine object using the vm name + vmName := *vm.Spec.Name + machineAddresses = append(machineAddresses, corev1.NodeAddress{ + Type: corev1.NodeInternalDNS, + Address: vmName, + }) + machineAddresses = append(machineAddresses, corev1.NodeAddress{ + Type: corev1.NodeHostName, + Address: vmName, + }) + + s.machine.Status.Addresses = machineAddresses + klog.V(3).Infof("%s: the machine status.addresses=%+v.", s.machine.Name, s.machine.Status.Addresses) s.providerStatus.Conditions = setNutanixProviderConditions([]metav1.Condition{condition}, s.providerStatus.Conditions) diff --git a/vendor/k8s.io/kubectl/pkg/cmd/util/factory.go b/vendor/k8s.io/kubectl/pkg/cmd/util/factory.go index cd806d62..e6414f3e 100644 --- a/vendor/k8s.io/kubectl/pkg/cmd/util/factory.go +++ b/vendor/k8s.io/kubectl/pkg/cmd/util/factory.go @@ -62,8 +62,10 @@ type Factory interface { // Returns a schema that can validate objects stored on disk. Validator(validationDirective string) (validation.Schema, error) - // OpenAPISchema returns the parsed openapi schema definition - OpenAPISchema() (openapi.Resources, error) + + // Used for retrieving openapi v2 resources. + openapi.OpenAPIResourcesGetter + // OpenAPIV3Schema returns a client for fetching parsed schemas for // any group version OpenAPIV3Client() (openapiclient.Client, error) diff --git a/vendor/k8s.io/kubectl/pkg/cmd/util/factory_client_access.go b/vendor/k8s.io/kubectl/pkg/cmd/util/factory_client_access.go index 3943fc30..6a1646b8 100644 --- a/vendor/k8s.io/kubectl/pkg/cmd/util/factory_client_access.go +++ b/vendor/k8s.io/kubectl/pkg/cmd/util/factory_client_access.go @@ -154,13 +154,8 @@ func (f *factoryImpl) Validator(validationDirective string) (validation.Schema, return validation.NullSchema{}, nil } - resources, err := f.OpenAPISchema() - if err != nil { - return nil, err - } - schema := validation.ConjunctiveSchema{ - validation.NewSchemaValidation(resources), + validation.NewSchemaValidation(f), validation.NoDoubleKeySchema{}, } @@ -219,5 +214,5 @@ func (f *factoryImpl) OpenAPIV3Client() (openapiclient.Client, error) { return nil, err } - return discovery.OpenAPIV3(), nil + return cached.NewClient(discovery.OpenAPIV3()), nil } diff --git a/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go b/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go index 43f72f54..6d38fade 100644 --- a/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go +++ b/vendor/k8s.io/kubectl/pkg/cmd/util/helpers.go @@ -425,13 +425,25 @@ func GetPodRunningTimeoutFlag(cmd *cobra.Command) (time.Duration, error) { type FeatureGate string const ( - ApplySet FeatureGate = "KUBECTL_APPLYSET" - CmdPluginAsSubcommand FeatureGate = "KUBECTL_ENABLE_CMD_SHADOW" - InteractiveDelete FeatureGate = "KUBECTL_INTERACTIVE_DELETE" + ApplySet FeatureGate = "KUBECTL_APPLYSET" + CmdPluginAsSubcommand FeatureGate = "KUBECTL_ENABLE_CMD_SHADOW" + InteractiveDelete FeatureGate = "KUBECTL_INTERACTIVE_DELETE" + OpenAPIV3Patch FeatureGate = "KUBECTL_OPENAPIV3_PATCH" + RemoteCommandWebsockets FeatureGate = "KUBECTL_REMOTE_COMMAND_WEBSOCKETS" ) +// IsEnabled returns true iff environment variable is set to true. +// All other cases, it returns false. func (f FeatureGate) IsEnabled() bool { - return os.Getenv(string(f)) == "true" + return strings.ToLower(os.Getenv(string(f))) == "true" +} + +// IsDisabled returns true iff environment variable is set to false. +// All other cases, it returns true. +// This function is used for the cases where feature is enabled by default, +// but it may be needed to provide a way to ability to disable this feature. +func (f FeatureGate) IsDisabled() bool { + return strings.ToLower(os.Getenv(string(f))) == "false" } func AddValidateFlags(cmd *cobra.Command) { diff --git a/vendor/k8s.io/kubectl/pkg/drain/drain.go b/vendor/k8s.io/kubectl/pkg/drain/drain.go index 5a5c9f44..1f6502ed 100644 --- a/vendor/k8s.io/kubectl/pkg/drain/drain.go +++ b/vendor/k8s.io/kubectl/pkg/drain/drain.go @@ -85,7 +85,14 @@ type Helper struct { DryRunStrategy cmdutil.DryRunStrategy // OnPodDeletedOrEvicted is called when a pod is evicted/deleted; for printing progress output + // Deprecated: use OnPodDeletionOrEvictionFinished instead OnPodDeletedOrEvicted func(pod *corev1.Pod, usingEviction bool) + + // OnPodDeletionOrEvictionFinished is called when a pod is eviction/deletetion is failed; for printing progress output + OnPodDeletionOrEvictionFinished func(pod *corev1.Pod, usingEviction bool, err error) + + // OnPodDeletionOrEvictionStarted is called when a pod eviction/deletion is started; for printing progress output + OnPodDeletionOrEvictionStarted func(pod *corev1.Pod, usingEviction bool) } type waitForDeleteParams struct { @@ -96,6 +103,7 @@ type waitForDeleteParams struct { usingEviction bool getPodFn func(string, string) (*corev1.Pod, error) onDoneFn func(pod *corev1.Pod, usingEviction bool) + onFinishFn func(pod *corev1.Pod, usingEviction bool, err error) globalTimeout time.Duration skipWaitForDeleteTimeoutSeconds int out io.Writer @@ -276,6 +284,9 @@ func (d *Helper) evictPods(pods []corev1.Pod, evictionGroupVersion schema.GroupV case cmdutil.DryRunServer: fmt.Fprintf(d.Out, "evicting pod %s/%s (server dry run)\n", pod.Namespace, pod.Name) default: + if d.OnPodDeletionOrEvictionStarted != nil { + d.OnPodDeletionOrEvictionStarted(&pod, true) + } fmt.Fprintf(d.Out, "evicting pod %s/%s\n", pod.Namespace, pod.Name) } select { @@ -334,6 +345,7 @@ func (d *Helper) evictPods(pods []corev1.Pod, evictionGroupVersion schema.GroupV usingEviction: true, getPodFn: getPodFn, onDoneFn: d.OnPodDeletedOrEvicted, + onFinishFn: d.OnPodDeletionOrEvictionFinished, globalTimeout: globalTimeout, skipWaitForDeleteTimeoutSeconds: d.SkipWaitForDeleteTimeoutSeconds, out: d.Out, @@ -377,6 +389,9 @@ func (d *Helper) deletePods(pods []corev1.Pod, getPodFn func(namespace, name str if err != nil && !apierrors.IsNotFound(err) { return err } + if d.OnPodDeletionOrEvictionStarted != nil { + d.OnPodDeletionOrEvictionStarted(&pod, false) + } } ctx := d.getContext() params := waitForDeleteParams{ @@ -387,6 +402,7 @@ func (d *Helper) deletePods(pods []corev1.Pod, getPodFn func(namespace, name str usingEviction: false, getPodFn: getPodFn, onDoneFn: d.OnPodDeletedOrEvicted, + onFinishFn: d.OnPodDeletionOrEvictionFinished, globalTimeout: globalTimeout, skipWaitForDeleteTimeoutSeconds: d.SkipWaitForDeleteTimeoutSeconds, out: d.Out, @@ -402,11 +418,16 @@ func waitForDelete(params waitForDeleteParams) ([]corev1.Pod, error) { for i, pod := range pods { p, err := params.getPodFn(pod.Namespace, pod.Name) if apierrors.IsNotFound(err) || (p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) { - if params.onDoneFn != nil { + if params.onFinishFn != nil { + params.onFinishFn(&pod, params.usingEviction, nil) + } else if params.onDoneFn != nil { params.onDoneFn(&pod, params.usingEviction) } continue } else if err != nil { + if params.onFinishFn != nil { + params.onFinishFn(&pod, params.usingEviction, err) + } return false, err } else { if shouldSkipPod(*p, params.skipWaitForDeleteTimeoutSeconds) { diff --git a/vendor/k8s.io/kubectl/pkg/util/openapi/openapi.go b/vendor/k8s.io/kubectl/pkg/util/openapi/openapi.go index de2fffad..74955da3 100644 --- a/vendor/k8s.io/kubectl/pkg/util/openapi/openapi.go +++ b/vendor/k8s.io/kubectl/pkg/util/openapi/openapi.go @@ -24,6 +24,13 @@ import ( "sigs.k8s.io/yaml" ) +// OpenAPIResourcesGetter represents a function to return +// OpenAPI V2 resource specifications. Used for lazy-loading +// these resource specifications. +type OpenAPIResourcesGetter interface { + OpenAPISchema() (Resources, error) +} + // Resources interface describe a resources provider, that can give you // resource based on group-version-kind. type Resources interface { diff --git a/vendor/k8s.io/kubectl/pkg/util/term/term.go b/vendor/k8s.io/kubectl/pkg/util/term/term.go index 6bcda59d..93a992fe 100644 --- a/vendor/k8s.io/kubectl/pkg/util/term/term.go +++ b/vendor/k8s.io/kubectl/pkg/util/term/term.go @@ -19,7 +19,8 @@ package term import ( "io" "os" - "runtime" + + "k8s.io/cli-runtime/pkg/printers" "github.com/moby/term" @@ -56,46 +57,23 @@ type TTY struct { // IsTerminalIn returns true if t.In is a terminal. Does not check /dev/tty // even if TryDev is set. func (t TTY) IsTerminalIn() bool { - return IsTerminal(t.In) + return printers.IsTerminal(t.In) } // IsTerminalOut returns true if t.Out is a terminal. Does not check /dev/tty // even if TryDev is set. func (t TTY) IsTerminalOut() bool { - return IsTerminal(t.Out) + return printers.IsTerminal(t.Out) } -// IsTerminal returns whether the passed object is a terminal or not -func IsTerminal(i interface{}) bool { - _, terminal := term.GetFdInfo(i) - return terminal -} +// IsTerminal returns whether the passed object is a terminal or not. +// Deprecated: use printers.IsTerminal instead. +var IsTerminal = printers.IsTerminal // AllowsColorOutput returns true if the specified writer is a terminal and // the process environment indicates color output is supported and desired. -func AllowsColorOutput(w io.Writer) bool { - if !IsTerminal(w) { - return false - } - - // https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals - if os.Getenv("TERM") == "dumb" { - return false - } - - // https://no-color.org/ - if _, nocolor := os.LookupEnv("NO_COLOR"); nocolor { - return false - } - - // On Windows WT_SESSION is set by the modern terminal component. - // Older terminals have poor support for UTF-8, VT escape codes, etc. - if runtime.GOOS == "windows" && os.Getenv("WT_SESSION") == "" { - return false - } - - return true -} +// Deprecated: use printers.AllowsColorOutput instead. +var AllowsColorOutput = printers.AllowsColorOutput // Safe invokes the provided function and will attempt to ensure that when the // function returns (or a termination signal is sent) that the terminal state diff --git a/vendor/k8s.io/kubectl/pkg/validation/validation.go b/vendor/k8s.io/kubectl/pkg/validation/validation.go index 3ba3213d..47c74e5b 100644 --- a/vendor/k8s.io/kubectl/pkg/validation/validation.go +++ b/vendor/k8s.io/kubectl/pkg/validation/validation.go @@ -29,14 +29,14 @@ import ( // schemaValidation validates the object against an OpenAPI schema. type schemaValidation struct { - resources openapi.Resources + resourcesGetter openapi.OpenAPIResourcesGetter } // NewSchemaValidation creates a new Schema that can be used // to validate objects. -func NewSchemaValidation(resources openapi.Resources) Schema { +func NewSchemaValidation(resourcesGetter openapi.OpenAPIResourcesGetter) Schema { return &schemaValidation{ - resources: resources, + resourcesGetter: resourcesGetter, } } @@ -56,7 +56,6 @@ func (v *schemaValidation) ValidateBytes(data []byte) error { if (gvk == schema.GroupVersionKind{Version: "v1", Kind: "List"}) { return utilerrors.NewAggregate(v.validateList(obj)) } - return utilerrors.NewAggregate(v.validateResource(obj, gvk)) } @@ -81,7 +80,12 @@ func (v *schemaValidation) validateList(object interface{}) []error { } func (v *schemaValidation) validateResource(obj interface{}, gvk schema.GroupVersionKind) []error { - resource := v.resources.LookupResource(gvk) + // This lazy-loads the OpenAPI V2 specifications, caching the specs. + resources, err := v.resourcesGetter.OpenAPISchema() + if err != nil { + return []error{err} + } + resource := resources.LookupResource(gvk) if resource == nil { // resource is not present, let's just skip validation. return nil diff --git a/vendor/modules.txt b/vendor/modules.txt index e039cace..34e51353 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -805,8 +805,8 @@ k8s.io/kube-openapi/pkg/spec3 k8s.io/kube-openapi/pkg/util/proto k8s.io/kube-openapi/pkg/util/proto/validation k8s.io/kube-openapi/pkg/validation/spec -# k8s.io/kubectl v0.29.0 => k8s.io/kubectl v0.28.2 -## explicit; go 1.20 +# k8s.io/kubectl v0.29.0 +## explicit; go 1.21 k8s.io/kubectl/pkg/cmd/util k8s.io/kubectl/pkg/drain k8s.io/kubectl/pkg/scheme @@ -1001,4 +1001,3 @@ sigs.k8s.io/structured-merge-diff/v4/value ## explicit; go 1.12 sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 -# k8s.io/kubectl => k8s.io/kubectl v0.28.2