VirtusLab / kubedrainer

Simple Kubernetes Node Drainer
Apache License 2.0
20 stars 10 forks source link

Region/InstanceID Expression Not Matching #9

Closed tgraskemper closed 3 years ago

tgraskemper commented 3 years ago

Attempting to spin this up in both a non-ASG managed cluster and one that is resulted in the same error.

│ {"level":"warn","time":1610478473,"message":"No config file found"}                                                                                                                                                                                        │
│ {"level":"info","time":1610478473,"message":"Running as server"}                                                                                                                                                                                           │
│ Error: Can't match expression '^/(?P<Region>[a-zA-Z0-9-]+)[a-z]/(?P<InstanceID>[a-zA-Z0-9-]+)$' to 'us-west-2b/i-0af01948154f55129'                                                                                                                        │
│ Usage:                                                                                                                                                                                                                                                     │
│   kubedrainer serve [flags]                                                                                                                                                                                                                                │
│ Flags:                                                                                                                                                                                                                                                     │
│       --cache-dir string               Default HTTP cache directory (default "/.kube/http-cache")                                                                                                                                                          │
│       --certificate-authority string   Path to a cert file for the certificate authority                                                                                                                                                                   │
│       --client-certificate string      Path to a client certificate file for TLS                                                                                                                                                                           │
│       --client-key string              Path to a client key file for TLS                                                                                                                                                                                   │
│       --cluster string                 The name of the kubeconfig cluster to use                                                                                                                                                                           │
│       --context string                 The name of the kubeconfig context to use                                                                                                                                                                           │
│       --delete-local-data              Continue even if there are pods using emptyDir (local data that will be deleted when the node is drained). (default true)                                                                                           │
│       --force                          Continue even if there are pods not managed by a ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet.                                                                                                  │
│       --grace-period int               Period of time in seconds given to each pod to terminate gracefully. If negative, the default value specified in the pod will be used. (default -1)                                                                 │
│   -h, --help                           help for serve                                                                                                                                                                                                      │
│       --ignore-daemonsets              Ignore DaemonSet-managed pods. (default true)                                                                                                                                                                       │
│       --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure                                                                                                  │
│       --instance-id string             AWS EC2 instance ID to terminate                                                                                                                                                                                    │
│       --kubeconfig string              Path to the kubeconfig file to use for CLI requests.                                                                                                                                                                │
│       --node string                    Kubernetes node name to drain                                                                                                                                                                                       │
│       --pod-selector string            Label selector to filter pods on the node                                                                                                                                                                           │
│       --profile string                 AWS Profile to use                                                                                                                                                                                                  │
│       --region string                  AWS Region to use                                                                                                                                                                                                   │
│       --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")     │
│   -l, --selector string                Selector (label query) to filter on                                                                                                                                                                                 │
│   -s, --server string                  The address and port of the Kubernetes API server                                                                                                                                                                   │
│       --timeout duration               The length of time to wait before giving up, zero means infinite (default 1m0s)                                                                                                                                     │
│       --token string                   Bearer token for authentication to the API server                                                                                                                                                                   │
│       --user string                    The name of the kubeconfig user to use                                                                                                                                                                              │
│ Global Flags:                                                                                                                                                                                                                                              │
│       --config string   config file (default is $HOME/.kubedrainer.yaml)                                                                                                                                                                                   │
│   -d, --debug           sets log level to debug                                                                                                                                                                                                            │
│ {"level":"fatal","time":1610478473,"message":"Can't match expression '^/(?P<Region>[a-zA-Z0-9-]+)[a-z]/(?P<InstanceID>[a-zA-Z0-9-]+)$' to 'us-west-2b/i-0af01948154f55129'"}

Looks like this just needs a backslash in the expression with the starting slash removed? https://github.com/VirtusLab/kubedrainer/blob/9a7d7d7e92ec9bcd6c0a3db75e05d8ef2ae7a76f/cmd/kubedrainer/serve.go#L204 ^(?P<Region>[a-zA-Z0-9-]+)[a-z]\/(?P<InstanceID>[a-zA-Z0-9-]+)$

pawelprazak commented 3 years ago

The \/ is redundant, the problem is that for whatever reason Kubernetes and/or AWS no longer start the node ID from /.

So there is a breaking change somewhere, in some version of Kubernetes API or AWS API.

Removing the first / will break it potentially for older versions, maybe we cloud make the first / optional.

pawelprazak commented 3 years ago

FYI: release is in progress, but Travis CI is very slow today, stuck in a queue...