Repository navigation
🌱 Step 2: support upstream hcloud-ccm secret/key conventions (II) - #1920
Conversation
This PR contains the basic changes. The opinionated features (like creating secretes twice), is in this PR: #1703
…-id-format-of-upstream-ccm-step1
…to tg/support-provider-id-format-of-upstream-ccm-step2
…-id-format-of-upstream-ccm-step1
…-upstream-ccm-step1' into tg/support-provider-id-format-of-upstream-ccm-step2
| HCloudToken string `json:"hcloudToken"` | ||
| // HetznerRobotUser defines the name of the key where the username for the Hetzner Robot API is stored. | ||
|
|
||
| // HetznerRobotUser defines the name of the key where the username for the Hetzner Robot API is |
There was a problem hiding this comment.
@janiskemper I added a comparison to the PR description. Both CCMS use the same keys for robot-user and robot-password.
@guettli so that means that both CCMs use the same key, but here in our default we have a different one than that?
In the code I don't see that we hardcode the value that you mention "robot-user". Therefore, this secret would actually be created wrongly if I specify something else with this configuration than "robot-user".
…-id-format-of-upstream-ccm-step2
| return names | ||
| } | ||
|
|
||
| func workloadClusterCompatibilityKeys(secretName, configuredKey, compatibilityKey string) []string { |
There was a problem hiding this comment.
plz explain this function in a comment. It's not trivial at all.
There was a problem hiding this comment.
@janiskemper I simplified the function and added a comment.
> plz explain this function in a comment. It's not trivial at all. #1920 (comment)
> I think this might be misleading to people. There is no action needed. We should rather invest in documentation rather than commenting here. People cannot easily change it here for example, but they need to go back to the mgt cluster. > > I'm fine with keeping the information about who owns the secret, but would remove these comments. #1920 (comment)
> can you add comments to all tests to make sure that it is clear what this test is about? #1920 (comment)
This reverts commit b8cc56b.
…-id-format-of-upstream-ccm-step2
janiskemper
left a comment
There was a problem hiding this comment.
LGTM. @Dhairya-Arora01 plz also review and tell us also if you don't understand something and want more explanation
…r switch (#2315) * 🐛 Make hcloudToken optional with the default "token" in v1beta2 The +optional and +kubebuilder:default markers of hcloudToken were on one line. controller-gen does not read two markers on one line. Neither marker applied, and since PR #1920 the field is required without a default: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/api/v1beta2/types.go#L165 Janis decided to make the field optional in v1beta2 with the default "token", which is the key upstream hcloud-ccm expects. The v1beta1 CRD does not change. The comment "Need to specify either HCloudToken or both HetznerRobotUser and HetznerRobotPassword" is removed. The HetznerCluster controller always reads the token, also for bare metal clusters: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hetznercluster_controller.go#L144 * 🌱 Align the v1beta2 timeout and failure reasons with the rest of the API Janis chose "TimeoutReached" for timeout reasons on PR #1935, and PR #2013 followed it: #1935 (comment) #2013 (comment) These v1beta2 reason values change: - HCloudMachine BootStateUnset, BootStateInitializing, EnablingRescue, BootingToRescue and BootingToRealOS end in "TimeoutReached" instead of "TimedOut". - HCloudRemediation "IrrecoverableServerCreateFailure" becomes "CreationFailedIrrecoverably". HCloudMachine already uses this reason for the same failure. - HetznerBareMetalHost "RebootingBMServerViaAPIFailed" becomes "RebootingViaAPIFailed", to match "RebootingViaSSHFailed". The v1beta2 reasons are not released yet. The deprecated v1beta1 reasons keep their values. RunningImageURLCommandTimedOut is left for after PR #2297, which renames it. * 🌱 Rename v1beta2 condition constants whose name does not match their value Only the Go names change. The reason values stay the same. - HCloudMachineServerOffTimeoutReason becomes HCloudMachineServerOffTimeoutReachedReason ("ServerOffTimeoutReached"). - HetznerBareMetalHostRebootSucceededTimeoutReachedOutReason becomes HetznerBareMetalHostRebootSucceededTimeoutReachedReason. - HetznerBareMetalMachineNotFoundReason becomes HetznerBareMetalMachineHostNotFoundReason. It is a reason of the HostReady condition and means that the host was not found. - HetznerBareMetalHostValidationFailedReason becomes HetznerBareMetalHostRootDeviceHintsValidationFailedReason, like the other reasons of the RootDeviceHintsValidated condition. - HCloudMachineProvisioningServerReason becomes HCloudMachineProvisioningReason ("Provisioning"). ControlPlaneEndpointSetV1Beta1Condition gets the type clusterv1.ConditionType, like the other deprecated v1beta1 conditions. It moves into its own block together with its reason ControlPlaneEndpointNotSetV1Beta1Reason, which was in the TargetClusterSecretReady block: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/api/v1beta2/conditions_const.go#L155-L166 * 🌱 Remove the unused credentialsVersion and network labels from the v1beta2 status CAPH never writes SecretStatus.Version (credentialsVersion). The v1beta1 code only set the reference and the data hash: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/api/v1beta1/hetznerbaremetalhost_types.go#L662-L674 NetworkStatus.Labels has the tag json:"-". It is never stored and nothing reads it. Both fields are removed from v1beta2. conversion-gen does not generate a public converter when a field does not exist in the target version. The v1beta1 to v1beta2 converters of SecretStatus and NetworkStatus are now written by hand and call the generated function. The fuzz test clears both fields, the same way it clears the deprecated failureReason. * 🌱 Use integer printcolumns for numbers and print the endpoint host in v1beta2 retryCount, retryLimit, timeoutSeconds and the CPU threads and RAM of HetznerBareMetalHost are integers in the schema. Their printcolumns used type=string. The Endpoint column of HetznerCluster printed the whole controlPlaneEndpoint object, which kubectl shows as map[host:... port:...]. It now prints the host: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/api/v1beta2/hetznercluster_types.go#L201 * 🌱 Stop setting observedGeneration on remediations that do not have the field patch.WithStatusObservedGeneration writes status.observedGeneration into the patch: https://github.com/kubernetes-sigs/cluster-api/blob/v1.13.4/util/patch/patch.go#L150-L154 HCloudRemediation and HetznerBareMetalRemediation do not have this field. The API server removes it before it stores the object. The next reconcile reads the object without the field again, and the patch helper sends a status patch every time. The comment said that the field is set only after a successful reconcile, but the option was passed every time: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hcloudremediation_controller.go#L311-L313 * 🌱 Handle the HCloudMachine boot state timeouts in one helper Six boot state handlers in server.go had the same timeout block. This is one of them: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/pkg/services/hcloud/server/server.go#L175-L213 The blocks differed only in the condition and the reason. remediateAfterTimeout replaces them. When the condition already exists, it keeps its reason and adds the timeout to its message. Then it remediates the CAPI Machine and sets the v1beta2 condition and the deprecated v1beta1 condition. There is one small difference. Two of the six blocks logged the error before they remediated the CAPI Machine, and four logged it after. The helper always logs first. * 🌱 Set the HCloudTokenAvailable condition in one helper Four controllers had the same deferred block. This is one of them: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hetznercluster_controller.go#L165-L186 The block sets HCloudTokenAvailable to False with "wrong hcloud token" when the reconcile returns ErrUnauthorized, and to True otherwise. setHCloudTokenAvailable in controllers/util.go replaces the four copies. The behavior does not change. * 🌱 Use the constant from the matching API version in two places The HCloud remediation passed the v1beta2 RemediationCooldownTriggeredReason to deprecatedv1beta1conditions.MarkFalse: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/pkg/services/hcloud/remediation/remediation.go#L398-L404 Both constants have the value "RemediationCooldownTriggered". Nothing changes at runtime. The bare metal remediation already uses the V1Beta1 constant: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/pkg/services/baremetal/remediation/remediation.go#L470-L476 namespace_skip.go was the last controller code that used the v1beta1 API package, apart from the scheme registration: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/namespace_skip.go#L45 infrav2.SkipNamespaceAnnotation has the same value, "capi.syself.com/skip-namespace". * 🌱 Remove unused constants, helpers and list hub markers from the v1beta2 API Nothing outside the api packages uses these: - SSHPrivateKeyNotFoundV1Beta1Reason, StorageDeviceNotFoundV1Beta1Reason, RescueSystemUnavailableV1Beta1Reason and CloudInitNotInstalledV1Beta1Reason - HetznerClusterLoadBalancerMissingControlPlaneEndpointReason, which has no caller since PR #2079 - ErrorMessageInvalidRootDeviceHints - ResourceLifecycleShared, NameKubernetesHetznerCloudProviderPrefix and ClusterHetznerCloudProviderTagKey in tags.go - HCloudNetworkSpec.IsZero. No field uses it through omitzero. To check one of them: git grep -n '\bNAME\b' -- ':!vendor' ':!api/v1beta1' The v1beta1 list types do not have ConvertTo or ConvertFrom. The Hub() markers on the 11 v1beta2 list types do not do anything: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/api/v1beta2/conversion.go#L19-L83 CAPI core v1beta2 marks only the objects: https://github.com/kubernetes-sigs/cluster-api/blob/v1.13.4/api/core/v1beta2/conversion.go#L27-L34 * 🌱 Remove unused v1beta1 and kubectl scheme registrations from tests controllers_suite_test.go and server_suite_test.go added types to the scheme of k8s.io/kubectl/pkg/scheme. No code in these packages reads that scheme. The tests use the scheme of test/helpers/envtest.go: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/controllers_suite_test.go#L222-L225 host_suite_test.go and reconcile_services_test.go registered the v1beta1 types on fake clients that only have v1beta2 objects. No code imports k8s.io/kubectl anymore. go mod tidy and go mod vendor remove it. * 🌱 Remove a dead test helper and duplicate rate limit tests CreateKubeconfigSecret in test/helpers does not have any callers. Two of the four reconcileRateLimit tests repeated the other two: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hetznercluster_controller_test.go#L1727-L1797 The two tests that stay also start with the deprecated HetznerAPIReachable condition set to False, which is the state a real rate limit leaves. Their "(v1beta2)" suffix is removed. The removed "time is not over" test also checked that waiting does not create HetznerAPIReachable when it is missing. A real rate limit always sets it. * 🌱 Assert both condition lists where the code writes both The code writes the v1beta2 condition and the deprecated v1beta1 condition in these places, but the tests checked only one of them: - Two HCloudRemediation tests checked only the deprecated MachineOwnerRemediated condition. The test above them checks both: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hcloudremediation_controller_test.go#L426 https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hcloudremediation_controller_test.go#L243-L248 - Two load balancer tests checked only the v1beta2 LoadBalancerReady condition: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/pkg/services/hcloud/loadbalancer/reconcile_services_test.go#L442-L445 IgnoreInsignificantHetznerClusterUpdates clears both condition lists, but only a change to the deprecated conditions had a test: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hcloudmachine_controller.go#L545-L551 * 🌱 Fix wrong and stale comments in the v1beta2 API Comments only, plus the regenerated CRD descriptions and one constant that moves to another section. Condition constants: - ServerCreateSucceeded said "Ready indicates Running". - LoadBalancerAttachFailed said "attached to network". server.go sets it when attaching the server to the load balancer fails: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/pkg/services/hcloud/server/server.go#L1300-L1310 - CredentialsAvailable said "cluster is in ready state". It reports the SSH secrets of the HetznerBareMetalHost. - LoadBalancerAttachingToNetworkFailed named the server instead of the load balancer. - The headers "HetznerCluster's v1beta2 conditions" and so on become "HetznerCluster conditions". - RemediationCooldownTriggeredReason moves to the section for conditions used by more than one resource type. Both remediation services set it on the CAPI Machine. API types. These said the opposite of the code: - skipCreatingHetznerSecretInWorkloadCluster said to set it to false to skip the secret. The controller skips it when the field is true: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/controllers/hetznercluster_controller.go#L498 - GetIPAddress said that it returns IPv6 first. It returns IPv4 first. - The phase lists of HCloudRemediation and HetznerBareMetalMachine named phases that CAPH never sets. - Both values of the load balancer algorithm and both target types said "default". round_robin is the default of controlPlaneLoadBalancer: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/api/v1beta2/types.go#L218-L221 The target type is a status field without a default. The others are typos, a zone that was missing in a list, and incomplete "known condition types" lists. * 🌱 Fix stale comments and names in the code and tests Comments, error messages and names only. Code: - The "Dual-write ... v1beta2 list" comments in both remediation services become one sentence about which list the CAPI MachineSet reads. - host.go said that a fatal error sets a FailureMessage on the HetznerBareMetalMachine. v1beta2 does not have failureMessage. The HetznerBareMetalMachine controller remediates the CAPI Machine instead: https://github.com/syself/cluster-api-provider-hetzner/blob/c57d11f325018a3e0ccaefcefaf13a35e594bd1d/pkg/services/baremetal/baremetal/baremetal.go#L328-L334 - The doc of SetErrorAndRemediate named DeleteMachineSucceededCondition, which does not exist. The error in SetRemediateMachineAnnotationToDeleteMachine named the wrong function. - FailureMessageMaintenanceMode becomes MaintenanceModeMessage. Tests: - Three comments and error messages named the old ...V1Beta2Condition constants of the v1beta1 API. - One comment described the old code instead of what the test checks. - Two tests were named "should fail with a wrong host selector label". The second one tests MatchExpressions and is now named "should fail with a wrong host selector operator". * Address Feedback
Next PR: 🌱 Set v1.1.x to main branch, and release. #1781
(merged Previous PR: 🌱 Support upstream providerId format (Step1) #1850)
This PR is step 2 of the work to support the upstream hcloud CCM for bare-metal clusters.
The core ProviderID migration work was moved to #1850. The refactor-only helper rename now lives in #1914.
This PR contains the follow-up changes that make the upstream CCM easier to use in practice.
Changes
tokenandhcloud, in addition to the configured key, so both CCM variants can read itspec.hetznerSecret.nameis nothcloud, create an additional workload-cluster secret namedhcloudfor upstream compatibilityhcloud, token keytoken, and Robot keysrobot-user/robot-passwordnoteentry to the workload-cluster secret to make it obvious that CAPH reconciles itComparing Secrets and Names of Keys
HCloud CCM Defaults (Helm Chart):
Hetzner Syself ccm (Helm Chart):
This is version II
We started the PR again, because it was too big.
First: #1703