From 1ac077d61a14cf19860b645b97e8085bd5303c1a Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Fri, 31 Mar 2023 10:40:55 -0500 Subject: [PATCH 01/41] added binaries, manifests, and edited makefile --- Makefile | 2 +- cmd/machine-os-builder/main.go | 26 +++++++++ cmd/machine-os-builder/start.go | 38 +++++++++++++ cmd/machine-os-builder/version.go | 32 +++++++++++ manifests/machineosbuilder/clusterrole.yaml | 57 +++++++++++++++++++ .../machineosbuilder/clusterrolebinding.yaml | 26 +++++++++ .../machineosbuilder/controllerconfig.yaml | 8 +++ manifests/machineosbuilder/deployment.yaml | 0 .../machineosbuilder/events-clusterrole.yaml | 8 +++ .../events-rolebinding-default.yaml | 12 ++++ .../events-rolebinding-target.yaml | 12 ++++ manifests/machineosbuilder/sa.yaml | 5 ++ 12 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 cmd/machine-os-builder/main.go create mode 100644 cmd/machine-os-builder/start.go create mode 100644 cmd/machine-os-builder/version.go create mode 100644 manifests/machineosbuilder/clusterrole.yaml create mode 100644 manifests/machineosbuilder/clusterrolebinding.yaml create mode 100644 manifests/machineosbuilder/controllerconfig.yaml create mode 100644 manifests/machineosbuilder/deployment.yaml create mode 100644 manifests/machineosbuilder/events-clusterrole.yaml create mode 100644 manifests/machineosbuilder/events-rolebinding-default.yaml create mode 100644 manifests/machineosbuilder/events-rolebinding-target.yaml create mode 100644 manifests/machineosbuilder/sa.yaml diff --git a/Makefile b/Makefile index ebd36f61c9..9386d6fabb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ MCO_COMPONENTS = daemon controller server operator -EXTRA_COMPONENTS = apiserver-watcher +EXTRA_COMPONENTS = apiserver-watcher machine-os-builder ALL_COMPONENTS = $(patsubst %,machine-config-%,$(MCO_COMPONENTS)) $(EXTRA_COMPONENTS) PREFIX ?= /usr GO111MODULE?=on diff --git a/cmd/machine-os-builder/main.go b/cmd/machine-os-builder/main.go new file mode 100644 index 0000000000..9e371d42a2 --- /dev/null +++ b/cmd/machine-os-builder/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + "fmt" + + "github.com/spf13/cobra" +) + +const componentName = "machine-config" + +var ( + rootCmd = &cobra.Command{ + Use: componentName, + Short: "Run Machine OS Builder", + Long: "", + } +) + +func init() { + rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine) +} + +func main() { + fmt.Println("Hello, World!") +} diff --git a/cmd/machine-os-builder/start.go b/cmd/machine-os-builder/start.go new file mode 100644 index 0000000000..ef85cfcc64 --- /dev/null +++ b/cmd/machine-os-builder/start.go @@ -0,0 +1,38 @@ +package main + +import ( + "flag" + + "github.com/golang/glog" + "github.com/openshift/machine-config-operator/pkg/version" + "github.com/spf13/cobra" +) + +var ( + startCmd = &cobra.Command{ + Use: "start", + Short: "Starts Machine OS Builder", + Long: "", + Run: runStartCmd, + } + + startOpts struct { + kubeconfig string + } +) + +func init() { + rootCmd.AddCommand(startCmd) + startCmd.PersistentFlags().StringVar(&startOpts.kubeconfig, "kubeconfig", "", "Kubeconfig file to access a remote cluster (testing only)") +} + +func runStartCmd(cmd *cobra.Command, args []string) { + flag.Set("logtostderr", "true") + flag.Parse() + + glog.V(2).Infof("Options parsed: %+v", startOpts) + + // To help debugging, immediately log version + glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + +} diff --git a/cmd/machine-os-builder/version.go b/cmd/machine-os-builder/version.go new file mode 100644 index 0000000000..7df9cb1323 --- /dev/null +++ b/cmd/machine-os-builder/version.go @@ -0,0 +1,32 @@ +package main + +import ( + "flag" + "fmt" + + "github.com/openshift/machine-config-operator/pkg/version" + "github.com/spf13/cobra" +) + +var ( + versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number of Machine OS Builder", + Long: `All software has versions. This is Machine OS Builder's.`, + Run: runVersionCmd, + } +) + +func init() { + rootCmd.AddCommand(versionCmd) +} + +func runVersionCmd(cmd *cobra.Command, args []string) { + flag.Set("logtostderr", "true") + flag.Parse() + + program := "MachineConfigController" + version := version.Raw + "-" + version.Hash + + fmt.Println(program, version) +} diff --git a/manifests/machineosbuilder/clusterrole.yaml b/manifests/machineosbuilder/clusterrole.yaml new file mode 100644 index 0000000000..74406df79a --- /dev/null +++ b/manifests/machineosbuilder/clusterrole.yaml @@ -0,0 +1,57 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: machine-os-builder +rules: +- apiGroups: [""] + resources: ["nodes"] + verbs: ["get", "list", "watch", "patch"] +- apiGroups: ["machineconfiguration.openshift.io"] + resources: ["*"] + verbs: ["*"] +- apiGroups: [""] + resources: ["configmaps", "secrets"] + verbs: ["*"] +- apiGroups: ["config.openshift.io"] + resources: ["images", "clusterversions", "featuregates", "nodes", "nodes/status"] + verbs: ["*"] +- apiGroups: ["config.openshift.io"] + resources: ["schedulers", "apiservers", "infrastructures", "imagedigestmirrorsets", "imagetagmirrorsets"] + verbs: ["get", "list", "watch"] +- apiGroups: ["operator.openshift.io"] + resources: ["imagecontentsourcepolicies"] + verbs: ["get", "list", "watch"] +- apiGroups: ["operator.openshift.io"] + resources: ["etcds"] + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: ["pods/eviction"] + verbs: ["create"] +- apiGroups: [""] + resources: ["pods"] + verbs: ["get", "list"] +- apiGroups: ["extensions"] + resources: ["daemonsets"] + verbs: ["get"] +- apiGroups: ["apps"] + resources: ["daemonsets"] + verbs: ["get"] +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + - subjectaccessreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - "*" diff --git a/manifests/machineosbuilder/clusterrolebinding.yaml b/manifests/machineosbuilder/clusterrolebinding.yaml new file mode 100644 index 0000000000..cd976e8a36 --- /dev/null +++ b/manifests/machineosbuilder/clusterrolebinding.yaml @@ -0,0 +1,26 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: machine-os-builder +roleRef: + kind: ClusterRole + name: machine-os-builder +subjects: +- kind: ServiceAccount + namespace: {{.TargetNamespace}} + name: machine-os-builder +--- +# Bind auth-delegator role to the MCC service account +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: machine-os-builder + namespace: {{.TargetNamespace}} +roleRef: + kind: ClusterRole + apiGroup: rbac.authorization.k8s.io + name: system:auth-delegator +subjects: +- kind: ServiceAccount + namespace: {{.TargetNamespace}} + name: machine-os-builder diff --git a/manifests/machineosbuilder/controllerconfig.yaml b/manifests/machineosbuilder/controllerconfig.yaml new file mode 100644 index 0000000000..c2a2f8b7f6 --- /dev/null +++ b/manifests/machineosbuilder/controllerconfig.yaml @@ -0,0 +1,8 @@ +apiVersion: machineconfiguration.openshift.io/v1 +kind: ControllerConfig +metadata: + name: machine-config-controller + annotations: + machineconfiguration.openshift.io/generated-by-version: "{{ .Version }}" +spec: +{{toYAML .ControllerConfig | toString | indent 2}} diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/manifests/machineosbuilder/events-clusterrole.yaml b/manifests/machineosbuilder/events-clusterrole.yaml new file mode 100644 index 0000000000..572457e46a --- /dev/null +++ b/manifests/machineosbuilder/events-clusterrole.yaml @@ -0,0 +1,8 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: machine-os-builder-events +rules: +- apiGroups: [""] + resources: ["events"] + verbs: ["create", "patch"] diff --git a/manifests/machineosbuilder/events-rolebinding-default.yaml b/manifests/machineosbuilder/events-rolebinding-default.yaml new file mode 100644 index 0000000000..f01fa0bd6c --- /dev/null +++ b/manifests/machineosbuilder/events-rolebinding-default.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: machine-os-builder-events + namespace: default +roleRef: + kind: ClusterRole + name: machine-os-builder-events +subjects: +- kind: ServiceAccount + namespace: {{.TargetNamespace}} + name: machine-os-builder diff --git a/manifests/machineosbuilder/events-rolebinding-target.yaml b/manifests/machineosbuilder/events-rolebinding-target.yaml new file mode 100644 index 0000000000..ef004f40cd --- /dev/null +++ b/manifests/machineosbuilder/events-rolebinding-target.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: machine-os-builder-events + namespace: {{.TargetNamespace}} +roleRef: + kind: ClusterRole + name: machine-os-builder-events +subjects: +- kind: ServiceAccount + namespace: {{.TargetNamespace}} + name: machine-os-builder diff --git a/manifests/machineosbuilder/sa.yaml b/manifests/machineosbuilder/sa.yaml new file mode 100644 index 0000000000..f69a1b84e3 --- /dev/null +++ b/manifests/machineosbuilder/sa.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + namespace: {{.TargetNamespace}} + name: machine-os-builder From 3145bafab335ba876a81cb266518a8e701e03803 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 3 Apr 2023 09:59:39 -0500 Subject: [PATCH 02/41] Rename deployment.yaml to eployment.yaml.to-be-implemented --- manifests/machineosbuilder/deployment.yaml | 0 manifests/machineosbuilder/eployment.yaml.to-be-implemented | 1 + 2 files changed, 1 insertion(+) delete mode 100644 manifests/machineosbuilder/deployment.yaml create mode 100644 manifests/machineosbuilder/eployment.yaml.to-be-implemented diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/manifests/machineosbuilder/eployment.yaml.to-be-implemented b/manifests/machineosbuilder/eployment.yaml.to-be-implemented new file mode 100644 index 0000000000..d3f5a12faa --- /dev/null +++ b/manifests/machineosbuilder/eployment.yaml.to-be-implemented @@ -0,0 +1 @@ + From ea1b01abe20f042b4d92a8099b65c3cbabbdd478 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:18:36 -0500 Subject: [PATCH 03/41] ignores deployment.yaml --- manifests/machineosbuilder/eployment.yaml.to-be-implemented | 1 - pkg/operator/render_test.go | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 manifests/machineosbuilder/eployment.yaml.to-be-implemented diff --git a/manifests/machineosbuilder/eployment.yaml.to-be-implemented b/manifests/machineosbuilder/eployment.yaml.to-be-implemented deleted file mode 100644 index d3f5a12faa..0000000000 --- a/manifests/machineosbuilder/eployment.yaml.to-be-implemented +++ /dev/null @@ -1 +0,0 @@ - diff --git a/pkg/operator/render_test.go b/pkg/operator/render_test.go index 3830b60460..c2ffc5d591 100644 --- a/pkg/operator/render_test.go +++ b/pkg/operator/render_test.go @@ -155,7 +155,9 @@ func TestRenderAllManifests(t *testing.T) { "on-prem/coredns-corefile.tmpl") // These are files in the manifest directory that we should ignore in this test. - ignored := sets.NewString("manifests.go") + ignored := sets.NewString( + "manifests.go", + "machineosbuilder/deployment.yaml") for _, manifestPath := range allManifests { manifestPath := manifestPath From b0b74261cf8bc5da70f9685c11b036f220ab9cdf Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Tue, 4 Apr 2023 10:29:08 -0500 Subject: [PATCH 04/41] fixed misnamed component name --- cmd/machine-os-builder/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/machine-os-builder/main.go b/cmd/machine-os-builder/main.go index 9e371d42a2..4d19bb323f 100644 --- a/cmd/machine-os-builder/main.go +++ b/cmd/machine-os-builder/main.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" ) -const componentName = "machine-config" +const componentName = "machine-os-builder" var ( rootCmd = &cobra.Command{ From 0fecb0203ff7575aec400980eaf18503f17df6fc Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:10:43 -0500 Subject: [PATCH 05/41] unignored deployment.yaml, added it to manifests --- manifests/machineosbuilder/deployment.yaml | 1 + pkg/operator/render_test.go | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 manifests/machineosbuilder/deployment.yaml diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml new file mode 100644 index 0000000000..f48cbb4b45 --- /dev/null +++ b/manifests/machineosbuilder/deployment.yaml @@ -0,0 +1 @@ +//TODO (dkhater) implement me! \ No newline at end of file diff --git a/pkg/operator/render_test.go b/pkg/operator/render_test.go index c2ffc5d591..3830b60460 100644 --- a/pkg/operator/render_test.go +++ b/pkg/operator/render_test.go @@ -155,9 +155,7 @@ func TestRenderAllManifests(t *testing.T) { "on-prem/coredns-corefile.tmpl") // These are files in the manifest directory that we should ignore in this test. - ignored := sets.NewString( - "manifests.go", - "machineosbuilder/deployment.yaml") + ignored := sets.NewString("manifests.go") for _, manifestPath := range allManifests { manifestPath := manifestPath From 40617c82e91e93483c5976b70ce7293271e2026b Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 10 Apr 2023 13:15:53 -0500 Subject: [PATCH 06/41] populated deployment.yaml simple --- manifests/machineosbuilder/deployment.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml index f48cbb4b45..9f0ab0b939 100644 --- a/manifests/machineosbuilder/deployment.yaml +++ b/manifests/machineosbuilder/deployment.yaml @@ -1 +1,13 @@ -//TODO (dkhater) implement me! \ No newline at end of file +apiVersion: apps/v1 +kind: Deployment +metadata: + name: machine-os-builder + namespace: {{.TargetNamespace}} +spec: + selector: + matchLabels: + k8s-app: machine-os-builder + template: + metadata: + labels: + k8s-app: machine-os-builder \ No newline at end of file From d6dda882ea9ef1d2af63202985abdc7b0c6ea3e2 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 10 Apr 2023 13:28:44 -0500 Subject: [PATCH 07/41] added sync function for mob --- pkg/operator/sync.go | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index d866dab91e..ce07503b9c 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -73,6 +73,14 @@ const ( mccClusterRoleBindingManifestPath = "manifests/machineconfigcontroller/clusterrolebinding.yaml" mccServiceAccountManifestPath = "manifests/machineconfigcontroller/sa.yaml" + // Machine OS Builder manifest paths + mobClusterRoleManifestPath = "manifests/machineosbuilder/clusterrole.yaml" + mobEventsClusterRoleManifestPath = "manifests/machineosbuilder/events-clusterrole.yaml" + mobEventsRoleBindingDefaultManifestPath = "manifests/machineosbuilder/events-rolebinding-default.yaml" + mobEventsRoleBindingTargetManifestPath = "manifests/machineosbuilder/events-rolebinding-target.yaml" + mobClusterRoleBindingManifestPath = "manifests/machineosbuilder/clusterrolebinding.yaml" + mobServiceAccountManifestPath = "manifests/machineosbuilder/sa.yaml" + // Machine Config Daemon manifest paths mcdClusterRoleManifestPath = "manifests/machineconfigdaemon/clusterrole.yaml" mcdEventsClusterRoleManifestPath = "manifests/machineconfigdaemon/events-clusterrole.yaml" @@ -668,6 +676,45 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { return optr.syncControllerConfig(config) } +func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { + paths := manifestPaths{ + clusterRoles: []string{ + mobClusterRoleManifestPath, + mobEventsClusterRoleManifestPath, + }, + roleBindings: []string{ + mobEventsRoleBindingDefaultManifestPath, + mobEventsRoleBindingTargetManifestPath, + }, + clusterRoleBindings: []string{ + mobClusterRoleBindingManifestPath, + }, + serviceAccounts: []string{ + mobServiceAccountManifestPath, + }, + } + if err := optr.applyManifests(config, paths); err != nil { + return fmt.Errorf("failed to apply machine os builder manifests: %w", err) + } + + mobBytes, err := renderAsset(config, "manifests/machineosbuilder/deployment.yaml") + if err != nil { + return err + } + mob := resourceread.ReadDeploymentV1OrDie(mobBytes) + + _, updated, err := mcoResourceApply.ApplyDeployment(optr.kubeClient.AppsV1(), mob) + if err != nil { + return err + } + if updated { + if err := optr.waitForDeploymentRollout(mob); err != nil { + return err + } + } + return optr.syncControllerConfig(config) +} + func (optr *Operator) syncMachineConfigDaemon(config *renderConfig) error { paths := manifestPaths{ clusterRoles: []string{ From 1b9177335a46aa3790c6bee08ec80b74b9c30a0f Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 10 Apr 2023 13:51:23 -0500 Subject: [PATCH 08/41] added items around images, builds, and ImageStreams --- manifests/machineosbuilder/clusterrole.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/manifests/machineosbuilder/clusterrole.yaml b/manifests/machineosbuilder/clusterrole.yaml index 74406df79a..7b0f1381b4 100644 --- a/manifests/machineosbuilder/clusterrole.yaml +++ b/manifests/machineosbuilder/clusterrole.yaml @@ -24,6 +24,15 @@ rules: - apiGroups: ["operator.openshift.io"] resources: ["etcds"] verbs: ["get", "list", "watch"] +- apiGroups: ["image.openshift.io"] + resources: ["images"] + verbs: ["get","list","watch","create","update","patch","delete"] +- apiGroups: ["image.openshift.io"] + resources: ["imagestreams"] + verbs: ["get","list","watch","create","update","patch","delete"] +- apiGroups: ["build.openshift.io"] + resources: ["builds","buildconfigs","buildconfigs/instantiate"] + verbs: ["get","list","watch","create","update","patch","delete"] - apiGroups: [""] resources: ["pods/eviction"] verbs: ["create"] From 6b83ad549503b3d4ab029ce3b22f0877df014bdb Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 1 May 2023 12:01:24 -1000 Subject: [PATCH 09/41] added image to deployment.yaml, got manifest to work --- manifests/machineosbuilder/deployment.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml index 9f0ab0b939..ae99bc5773 100644 --- a/manifests/machineosbuilder/deployment.yaml +++ b/manifests/machineosbuilder/deployment.yaml @@ -2,12 +2,18 @@ apiVersion: apps/v1 kind: Deployment metadata: name: machine-os-builder - namespace: {{.TargetNamespace}} spec: + replicas: 1 selector: matchLabels: k8s-app: machine-os-builder template: metadata: labels: - k8s-app: machine-os-builder \ No newline at end of file + k8s-app: machine-os-builder + spec: + containers: + - name: hello-openshift + image: openshift/hello-openshift:latest + ports: + - containerPort: 80 \ No newline at end of file From 59d65dcbc5e18d38389669bda1a2f9a64040e4d6 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 18 May 2023 13:23:01 -0500 Subject: [PATCH 10/41] changed hack cluster push --- hack/cluster-push.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hack/cluster-push.sh b/hack/cluster-push.sh index 437f07f925..47f6b1d051 100755 --- a/hack/cluster-push.sh +++ b/hack/cluster-push.sh @@ -34,10 +34,12 @@ if [[ "${podman:-}" =~ "docker" ]]; then else imgstorage="containers-storage:" fi -skopeo copy --dest-tls-verify=false --dest-creds unused:${secret} "${imgstorage}${LOCAL_IMGNAME}" "docker://${registry}/${REMOTE_IMGNAME}" -digest=$(skopeo inspect --creds unused:${secret} --tls-verify=false docker://${registry}/${REMOTE_IMGNAME} | jq -r .Digest) -imageid=${REMOTE_IMGNAME}@${digest} +podman tag "$LOCAL_IMGNAME" "$registry/$REMOTE_IMGNAME" +podman push --tls-verify=false --creds "unused:$secret" "$LOCAL_IMGNAME" "$registry/$REMOTE_IMGNAME" + +digest="$(skopeo inspect --creds "unused:${secret}" --tls-verify=false "docker://${registry}/${REMOTE_IMGNAME}" | jq -r '.Digest')" +imageid="${REMOTE_IMGNAME}@${digest}" oc project openshift-machine-config-operator From 1f534933ce1f8881b7ac9ffe8f2132987777f878 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 18 May 2023 13:25:51 -0500 Subject: [PATCH 11/41] added namespace, additional configuration for mob --- manifests/machineosbuilder/deployment.yaml | 1 + pkg/operator/operator.go | 1 + pkg/operator/sync.go | 1 + 3 files changed, 3 insertions(+) diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml index ae99bc5773..ed5c9fa33a 100644 --- a/manifests/machineosbuilder/deployment.yaml +++ b/manifests/machineosbuilder/deployment.yaml @@ -2,6 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: machine-os-builder + namespace: {{.TargetNamespace}} spec: replicas: 1 selector: diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 8eaa42e1f9..c66d77c59a 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -362,6 +362,7 @@ func (optr *Operator) sync(key string) error { {"MachineConfigDaemon", optr.syncMachineConfigDaemon}, {"MachineConfigController", optr.syncMachineConfigController}, {"MachineConfigServer", optr.syncMachineConfigServer}, + {"MachineOSBuilder", optr.syncMachineOSBuilder}, // this check must always run last since it makes sure the pools are in sync/upgrading correctly {"RequiredPools", optr.syncRequiredMachineConfigPools}, } diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index ce07503b9c..869cd891e4 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -677,6 +677,7 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { } func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { + glog.Infof("Performing Machine OS Builder sync") paths := manifestPaths{ clusterRoles: []string{ mobClusterRoleManifestPath, From 8038b75aed245b67f89080a7f5a7b4591ffe55a0 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 18 May 2023 13:55:01 -0500 Subject: [PATCH 12/41] modified hack cluster script --- hack/cluster-push.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hack/cluster-push.sh b/hack/cluster-push.sh index 47f6b1d051..d1b296019b 100755 --- a/hack/cluster-push.sh +++ b/hack/cluster-push.sh @@ -34,6 +34,7 @@ if [[ "${podman:-}" =~ "docker" ]]; then else imgstorage="containers-storage:" fi +# skopeo copy --dest-tls-verify=false --dest-creds unused:${secret} "${imgstorage}${LOCAL_IMGNAME}" "docker://${registry}/${REMOTE_IMGNAME}" podman tag "$LOCAL_IMGNAME" "$registry/$REMOTE_IMGNAME" podman push --tls-verify=false --creds "unused:$secret" "$LOCAL_IMGNAME" "$registry/$REMOTE_IMGNAME" From a69e82fa83e69bb19da077fcfc9f81a96357e27f Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Tue, 23 May 2023 10:48:31 -0500 Subject: [PATCH 13/41] added code to look at pools, comments --- manifests/machineosbuilder/deployment.yaml | 7 ++- pkg/operator/sync.go | 58 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml index ed5c9fa33a..06cbd4c6e4 100644 --- a/manifests/machineosbuilder/deployment.yaml +++ b/manifests/machineosbuilder/deployment.yaml @@ -14,7 +14,10 @@ spec: k8s-app: machine-os-builder spec: containers: - - name: hello-openshift + - name: machine-os-builder image: openshift/hello-openshift:latest ports: - - containerPort: 80 \ No newline at end of file + - containerPort: 80 + args: + - "start" + - "--resourcelock-namespace={{.TargetNamespace}}" diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 869cd891e4..4a3ce92136 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -44,6 +44,7 @@ import ( const ( requiredForUpgradeMachineConfigPoolLabelKey = "operator.machineconfiguration.openshift.io/required-for-upgrade" + onClusterBuildPoolLabelKey = "on-cluster-build" ) var ( @@ -678,6 +679,7 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { glog.Infof("Performing Machine OS Builder sync") + paths := manifestPaths{ clusterRoles: []string{ mobClusterRoleManifestPath, @@ -713,6 +715,62 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { return err } } + + var lastErr error + if err := wait.Poll(time.Second, 10*time.Minute, func() (bool, error) { + if lastErr != nil { + co, err := optr.fetchClusterOperator() + if err != nil { + errs := kubeErrs.NewAggregate([]error{err, lastErr}) + lastErr = fmt.Errorf("failed to fetch clusteroperator: %w", errs) + return false, nil + } + if co == nil { + glog.Warning("no clusteroperator for machine-config") + return false, nil + } + optr.setOperatorStatusExtension(&co.Status, lastErr) + _, err = optr.configClient.ConfigV1().ClusterOperators().UpdateStatus(context.TODO(), co, metav1.UpdateOptions{}) + if err != nil { + errs := kubeErrs.NewAggregate([]error{err, lastErr}) + lastErr = fmt.Errorf("failed to update clusteroperator: %w", errs) + return false, nil + } + } + + fmt.Printf("cluster operator fetched") + pools, err := optr.mcpLister.List(labels.Everything()) + if err != nil { + return false, nil + } + for _, pool := range pools { + fmt.Printf("Pool Name wasssup: %s\n", pool.Name) + fmt.Printf("checking if pool is degraded") + degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) + if degraded { + lastErr = fmt.Errorf("error pool %s is not ready, retrying. Status: (pool degraded: %v total: %d, ready %d, updated: %d, unavailable: %d)", pool.Name, degraded, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount) + glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) + syncerr := optr.syncUpgradeableStatus() + if syncerr != nil { + glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) + } + return false, nil + } + fmt.Printf("checking if pool has required on-cluster-build label") + _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] + if hasRequiredPoolLabel { + fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) + } + } + return true, nil + }); err != nil { + if err == wait.ErrWaitTimeout { + glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) + errs := kubeErrs.NewAggregate([]error{err, lastErr}) + return fmt.Errorf("error during syncRequiredMachineConfigPools: %w", errs) + } + return err + } return optr.syncControllerConfig(config) } From cd131fdca631f4d01f108ad9467d5deb82bf971c Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Tue, 23 May 2023 12:32:42 -0500 Subject: [PATCH 14/41] testing by removing comment --- pkg/operator/sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 4a3ce92136..ad10f5f2b0 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -744,7 +744,7 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { return false, nil } for _, pool := range pools { - fmt.Printf("Pool Name wasssup: %s\n", pool.Name) + fmt.Printf("Pool Name: %s\n", pool.Name) fmt.Printf("checking if pool is degraded") degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) if degraded { From 53aa55d723789f09a1be62a4b66aa0560dababe4 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Tue, 23 May 2023 13:34:45 -0500 Subject: [PATCH 15/41] added newlines --- pkg/operator/sync.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index ad10f5f2b0..b7fc4e2c14 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -738,14 +738,14 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } } - fmt.Printf("cluster operator fetched") + fmt.Printf("cluster operator fetched\n") pools, err := optr.mcpLister.List(labels.Everything()) if err != nil { return false, nil } for _, pool := range pools { fmt.Printf("Pool Name: %s\n", pool.Name) - fmt.Printf("checking if pool is degraded") + fmt.Printf("checking if pool is degraded\n") degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) if degraded { lastErr = fmt.Errorf("error pool %s is not ready, retrying. Status: (pool degraded: %v total: %d, ready %d, updated: %d, unavailable: %d)", pool.Name, degraded, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount) @@ -756,7 +756,7 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } return false, nil } - fmt.Printf("checking if pool has required on-cluster-build label") + fmt.Printf("checking if pool has required on-cluster-build label\n") _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] if hasRequiredPoolLabel { fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) From 4dc1a63541dec67e2c171a136f248a6669376586 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Tue, 23 May 2023 15:33:17 -0500 Subject: [PATCH 16/41] seeing why on-cluster-build label isnt showing up --- pkg/operator/sync.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index b7fc4e2c14..2e26b73147 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -737,8 +737,8 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { return false, nil } } - fmt.Printf("cluster operator fetched\n") + pools, err := optr.mcpLister.List(labels.Everything()) if err != nil { return false, nil @@ -756,12 +756,13 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } return false, nil } - fmt.Printf("checking if pool has required on-cluster-build label\n") - _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] - if hasRequiredPoolLabel { - fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) - } + // fmt.Printf("checking if pool has required on-cluster-build label\n") + // _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] + // if hasRequiredPoolLabel { + // fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) + // } } + // fmt.Printf("on-cluster-build label is found\n") return true, nil }); err != nil { if err == wait.ErrWaitTimeout { From bf492ec15b1760b8456529af9928e39f67c37384 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Wed, 24 May 2023 09:42:40 -0500 Subject: [PATCH 17/41] trying separating function --- pkg/operator/sync.go | 129 +++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 54 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 2e26b73147..0c88efae22 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -716,63 +716,84 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } } - var lastErr error - if err := wait.Poll(time.Second, 10*time.Minute, func() (bool, error) { - if lastErr != nil { - co, err := optr.fetchClusterOperator() - if err != nil { - errs := kubeErrs.NewAggregate([]error{err, lastErr}) - lastErr = fmt.Errorf("failed to fetch clusteroperator: %w", errs) - return false, nil - } - if co == nil { - glog.Warning("no clusteroperator for machine-config") - return false, nil - } - optr.setOperatorStatusExtension(&co.Status, lastErr) - _, err = optr.configClient.ConfigV1().ClusterOperators().UpdateStatus(context.TODO(), co, metav1.UpdateOptions{}) - if err != nil { - errs := kubeErrs.NewAggregate([]error{err, lastErr}) - lastErr = fmt.Errorf("failed to update clusteroperator: %w", errs) - return false, nil - } - } - fmt.Printf("cluster operator fetched\n") + // var lastErr error + // if err := wait.Poll(time.Second, 10*time.Minute, func() (bool, error) { + // if lastErr != nil { + // co, err := optr.fetchClusterOperator() + // if err != nil { + // errs := kubeErrs.NewAggregate([]error{err, lastErr}) + // lastErr = fmt.Errorf("failed to fetch clusteroperator: %w", errs) + // return false, nil + // } + // if co == nil { + // glog.Warning("no clusteroperator for machine-config") + // return false, nil + // } + // optr.setOperatorStatusExtension(&co.Status, lastErr) + // _, err = optr.configClient.ConfigV1().ClusterOperators().UpdateStatus(context.TODO(), co, metav1.UpdateOptions{}) + // if err != nil { + // errs := kubeErrs.NewAggregate([]error{err, lastErr}) + // lastErr = fmt.Errorf("failed to update clusteroperator: %w", errs) + // return false, nil + // } + // fmt.Printf("cluster operator fetched\n") + // } + + // pools, err := optr.mcpLister.List(labels.Everything()) + // if err != nil { + // return false, nil + // } + // for _, pool := range pools { + // fmt.Printf("Pool Name: %s\n", pool.Name) + // fmt.Printf("checking if pool is degraded\n") + // degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) + // if degraded { + // lastErr = fmt.Errorf("error pool %s is not ready, retrying. Status: (pool degraded: %v total: %d, ready %d, updated: %d, unavailable: %d)", pool.Name, degraded, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount) + // glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) + // syncerr := optr.syncUpgradeableStatus() + // if syncerr != nil { + // glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) + // } + // return false, nil + // } + // fmt.Printf("checking if pool has required on-cluster-build label\n") + // _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] + // if hasRequiredPoolLabel { + // fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) + // } + // } + // fmt.Printf("on-cluster-build label is found\n") + // return true, nil + // }); err != nil { + // if err == wait.ErrWaitTimeout { + // glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) + // errs := kubeErrs.NewAggregate([]error{err, lastErr}) + // return fmt.Errorf("error during syncRequiredMachineConfigPools: %w", errs) + // } + // return err + // } + return optr.syncControllerConfig(config) +} - pools, err := optr.mcpLister.List(labels.Everything()) - if err != nil { - return false, nil - } - for _, pool := range pools { - fmt.Printf("Pool Name: %s\n", pool.Name) - fmt.Printf("checking if pool is degraded\n") - degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) - if degraded { - lastErr = fmt.Errorf("error pool %s is not ready, retrying. Status: (pool degraded: %v total: %d, ready %d, updated: %d, unavailable: %d)", pool.Name, degraded, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount) - glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) - syncerr := optr.syncUpgradeableStatus() - if syncerr != nil { - glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) - } - return false, nil - } - // fmt.Printf("checking if pool has required on-cluster-build label\n") - // _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] - // if hasRequiredPoolLabel { - // fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) - // } - } - // fmt.Printf("on-cluster-build label is found\n") - return true, nil - }); err != nil { - if err == wait.ErrWaitTimeout { - glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) - errs := kubeErrs.NewAggregate([]error{err, lastErr}) - return fmt.Errorf("error during syncRequiredMachineConfigPools: %w", errs) +func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { + + pools, err := optr.mcpLister.List(labels.Everything()) + if err != nil { + glog.Fatal(err) + } + for _, pool := range pools { + labels := pool.GetLabels() + if val, ok := labels["on-cluster-build"]; ok && val == "true" { + fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) + startBuildControllerPod() } - return err } - return optr.syncControllerConfig(config) + + return nil +} + +func startBuildControllerPod() { + fmt.Printf("hello this starts the build controller pod\n") } func (optr *Operator) syncMachineConfigDaemon(config *renderConfig) error { From 0297f1753c0dc31ec52ed263520296c48bc1a4b4 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Tue, 6 Jun 2023 16:53:57 -0500 Subject: [PATCH 18/41] oc line issues --- pkg/operator/sync.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 0c88efae22..961fba3170 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -775,22 +775,22 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { return optr.syncControllerConfig(config) } -func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { - - pools, err := optr.mcpLister.List(labels.Everything()) - if err != nil { - glog.Fatal(err) - } - for _, pool := range pools { - labels := pool.GetLabels() - if val, ok := labels["on-cluster-build"]; ok && val == "true" { - fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) - startBuildControllerPod() - } - } - - return nil -} +// func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { + +// pools, err := optr.mcpLister.List(labels.Everything()) +// if err != nil { +// glog.Fatal(err) +// } +// for _, pool := range pools { +// labels := pool.GetLabels() +// if val, ok := labels["on-cluster-build"]; ok && val == "true" { +// fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) +// startBuildControllerPod() +// } +// } + +// return nil +// } func startBuildControllerPod() { fmt.Printf("hello this starts the build controller pod\n") From 9ec92c6f5e5062037c9b168184bf7a89d5a93afb Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 09:51:25 -0500 Subject: [PATCH 19/41] seeing if pools will get output --- pkg/operator/sync.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 961fba3170..a1e4fead5b 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -716,6 +716,18 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } } + pools, err := optr.mcpLister.List(labels.Everything()) + if err != nil { + glog.Fatal(err) + } + for _, pool := range pools { + labels := pool.GetLabels() + if val, ok := labels["on-cluster-build"]; ok && val == "true" { + fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) + startBuildControllerPod() + } + } + // var lastErr error // if err := wait.Poll(time.Second, 10*time.Minute, func() (bool, error) { // if lastErr != nil { From 7a00e49a7c75485e98639df140d634b5bcea4eb8 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 09:59:32 -0500 Subject: [PATCH 20/41] testing if local code is being seen --- pkg/operator/sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index a1e4fead5b..f695084840 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -678,7 +678,7 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { } func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { - glog.Infof("Performing Machine OS Builder sync") + glog.Infof("Performing Machine OS Builder synccccc") paths := manifestPaths{ clusterRoles: []string{ From 88a3c831d1afd1c0c646be997075dfa590a66cd3 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 10:43:51 -0500 Subject: [PATCH 21/41] got it to see local code --- pkg/operator/sync.go | 88 +++++++------------------------------------- 1 file changed, 13 insertions(+), 75 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index f695084840..982bce94a3 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -678,7 +678,7 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { } func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { - glog.Infof("Performing Machine OS Builder synccccc") + glog.Infof("Performing Machine OS Builder sync") paths := manifestPaths{ clusterRoles: []string{ @@ -716,6 +716,17 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } } + err = optr.checkForOnClusterBuild(config) + if err != nil { + return err + } + + return optr.syncControllerConfig(config) +} + +func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { + glog.Infof("Checking for On Cluster Build Tag") + pools, err := optr.mcpLister.List(labels.Everything()) if err != nil { glog.Fatal(err) @@ -728,82 +739,9 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } } - // var lastErr error - // if err := wait.Poll(time.Second, 10*time.Minute, func() (bool, error) { - // if lastErr != nil { - // co, err := optr.fetchClusterOperator() - // if err != nil { - // errs := kubeErrs.NewAggregate([]error{err, lastErr}) - // lastErr = fmt.Errorf("failed to fetch clusteroperator: %w", errs) - // return false, nil - // } - // if co == nil { - // glog.Warning("no clusteroperator for machine-config") - // return false, nil - // } - // optr.setOperatorStatusExtension(&co.Status, lastErr) - // _, err = optr.configClient.ConfigV1().ClusterOperators().UpdateStatus(context.TODO(), co, metav1.UpdateOptions{}) - // if err != nil { - // errs := kubeErrs.NewAggregate([]error{err, lastErr}) - // lastErr = fmt.Errorf("failed to update clusteroperator: %w", errs) - // return false, nil - // } - // fmt.Printf("cluster operator fetched\n") - // } - - // pools, err := optr.mcpLister.List(labels.Everything()) - // if err != nil { - // return false, nil - // } - // for _, pool := range pools { - // fmt.Printf("Pool Name: %s\n", pool.Name) - // fmt.Printf("checking if pool is degraded\n") - // degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) - // if degraded { - // lastErr = fmt.Errorf("error pool %s is not ready, retrying. Status: (pool degraded: %v total: %d, ready %d, updated: %d, unavailable: %d)", pool.Name, degraded, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount) - // glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) - // syncerr := optr.syncUpgradeableStatus() - // if syncerr != nil { - // glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) - // } - // return false, nil - // } - // fmt.Printf("checking if pool has required on-cluster-build label\n") - // _, hasRequiredPoolLabel := pool.Labels[onClusterBuildPoolLabelKey] - // if hasRequiredPoolLabel { - // fmt.Printf("Pool Name: %s\n", onClusterBuildPoolLabelKey) - // } - // } - // fmt.Printf("on-cluster-build label is found\n") - // return true, nil - // }); err != nil { - // if err == wait.ErrWaitTimeout { - // glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) - // errs := kubeErrs.NewAggregate([]error{err, lastErr}) - // return fmt.Errorf("error during syncRequiredMachineConfigPools: %w", errs) - // } - // return err - // } - return optr.syncControllerConfig(config) + return nil } -// func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { - -// pools, err := optr.mcpLister.List(labels.Everything()) -// if err != nil { -// glog.Fatal(err) -// } -// for _, pool := range pools { -// labels := pool.GetLabels() -// if val, ok := labels["on-cluster-build"]; ok && val == "true" { -// fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) -// startBuildControllerPod() -// } -// } - -// return nil -// } - func startBuildControllerPod() { fmt.Printf("hello this starts the build controller pod\n") } From eeffee85a2e249295e2fedc9253c8b6f767ac475 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 11:02:12 -0500 Subject: [PATCH 22/41] adding logging for what pools and labels --- pkg/operator/sync.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 982bce94a3..5b91e3f916 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -736,6 +736,13 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { if val, ok := labels["on-cluster-build"]; ok && val == "true" { fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) startBuildControllerPod() + } else { + glog.Infof("Pool %s is not labeled with 'on-cluster-build'.\n", pool.Name) + } + + glog.Infof("Labels found for pool %s:", pool.Name) + for key, value := range labels { + glog.Infof("Label: %s, Value: %s", key, value) } } From 43441d9b00362bd9d55c1fe05e2951117f78d069 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 11:33:18 -0500 Subject: [PATCH 23/41] the condition val == true is not evaluating to true because the label value is not exactly equal to true. --- pkg/operator/sync.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 5b91e3f916..abb4e9ba3d 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -733,17 +733,13 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { } for _, pool := range pools { labels := pool.GetLabels() - if val, ok := labels["on-cluster-build"]; ok && val == "true" { + glog.Infof("Pool found: %s \n", pool.Name) + if val, ok := labels["on-cluster-build"]; ok && val != "" { fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) startBuildControllerPod() } else { glog.Infof("Pool %s is not labeled with 'on-cluster-build'.\n", pool.Name) } - - glog.Infof("Labels found for pool %s:", pool.Name) - for key, value := range labels { - glog.Infof("Label: %s, Value: %s", key, value) - } } return nil From 26ccab5c8368dda2fb53d2d1d8acce0589dea6c6 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 11:54:49 -0500 Subject: [PATCH 24/41] changing if statement --- pkg/operator/sync.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index abb4e9ba3d..6280373b2a 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -732,9 +732,9 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { glog.Fatal(err) } for _, pool := range pools { - labels := pool.GetLabels() + // labels := pool.GetLabels() glog.Infof("Pool found: %s \n", pool.Name) - if val, ok := labels["on-cluster-build"]; ok && val != "" { + if pool.Name == "on-cluster-build" { fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) startBuildControllerPod() } else { From 317fc95a37eeb1f00860ebfa5c0f0e779a3709ce Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Wed, 7 Jun 2023 12:13:25 -0500 Subject: [PATCH 25/41] found on-cluster-build when tag is applied and unapplied --- pkg/operator/sync.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 6280373b2a..6753b00170 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -732,13 +732,10 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { glog.Fatal(err) } for _, pool := range pools { - // labels := pool.GetLabels() glog.Infof("Pool found: %s \n", pool.Name) if pool.Name == "on-cluster-build" { fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) startBuildControllerPod() - } else { - glog.Infof("Pool %s is not labeled with 'on-cluster-build'.\n", pool.Name) } } From 98119ddb9ee7fa79201091f8e331ce2e9fd155ae Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Thu, 8 Jun 2023 13:26:37 -0500 Subject: [PATCH 26/41] added node controller opt in functionality. should pause node controller with label --- pkg/controller/node/node_controller.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/controller/node/node_controller.go b/pkg/controller/node/node_controller.go index 51a2cb34fc..4df7ee1dbb 100644 --- a/pkg/controller/node/node_controller.go +++ b/pkg/controller/node/node_controller.go @@ -65,6 +65,9 @@ const ( // schedulerCRName that we're interested in watching. schedulerCRName = "cluster" + + // LayeringEnabledPoolLabel is the label that enables the "layered" workflow path for a pool. + LayeringEnabledPoolLabel = "machineconfiguration.openshift.io/layering-enabled" ) // Controller defines the node controller. @@ -1173,3 +1176,22 @@ func getErrorString(err error) string { } return "" } + +// shouldApplyConfigToPool checks if the node-controller should apply configurations to the given pool. +// If a pool is labeled with 'LayeringEnabledPoolLabel', it returns false indicating that no action should be taken. +// Otherwise, it returns true indicating that the node-controller can proceed with applying configurations to the pool. +func shouldApplyConfigToPool(pool *mcfgv1.MachineConfigPool) bool { + labels := pool.GetLabels() + _, exists := labels[LayeringEnabledPoolLabel] + return !exists +} + +func updateCandidateMachines(pool *mcfgv1.MachineConfigPool, candidates []*corev1.Node, capacity uint) error { + if !shouldApplyConfigToPool(pool) { + // Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything. + return nil + } + + // Continue with the rest of the update logic for the pool + return nil +} From af2649d34d772f06a963e08de69af8c517b88159 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 9 Mar 2023 11:44:31 -0600 Subject: [PATCH 27/41] Deleting SSH keys / password hashes should not degrade MachineConfigPool / node --- pkg/daemon/update.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index 9518cb4464..5ab4be262e 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -823,9 +823,7 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition Passwd Groups section contains changes") } if !reflect.DeepEqual(oldIgn.Passwd.Users, newIgn.Passwd.Users) { - if len(oldIgn.Passwd.Users) > 0 && len(newIgn.Passwd.Users) == 0 { - return nil, fmt.Errorf("ignition passwd user section contains unsupported changes: user core may not be deleted") - } + newEmpty := len(newIgn.Passwd.Users) == 0 // there is an update to Users, we must verify that it is ONLY making an acceptable // change to the SSHAuthorizedKeys for the user "core" for _, user := range newIgn.Passwd.Users { @@ -833,11 +831,13 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition passwd user section contains unsupported changes: non-core user") } } - - glog.Infof("user data to be verified before ssh update: %v", newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]) - if err := verifyUserFields(newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]); err != nil { - return nil, err + if !newEmpty { + glog.Infof("user data to be verified before ssh update: %v", newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]) + if err := verifyUserFields(newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]); err != nil { + return nil, err + } } + } } From 92bbc233f08bdd2014625a4ea3ee8390d9e207db Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 16 Mar 2023 13:26:25 -0600 Subject: [PATCH 28/41] removed unit test to verify that another user that isnt core cannot be added --- pkg/daemon/update_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkg/daemon/update_test.go b/pkg/daemon/update_test.go index 926ab69a89..a1887d06b4 100644 --- a/pkg/daemon/update_test.go +++ b/pkg/daemon/update_test.go @@ -373,16 +373,6 @@ func TestReconcilableSSH(t *testing.T) { _, errMsg := reconcilable(oldMcfg, newMcfg) checkReconcilableResults(t, "SSH", errMsg) - // Check that updating User with User that is not core is not supported - tempUser2 := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"1234"}} - oldIgnCfg.Passwd.Users = append(oldIgnCfg.Passwd.Users, tempUser2) - oldMcfg = helpers.CreateMachineConfigFromIgnition(oldIgnCfg) - tempUser3 := ign3types.PasswdUser{Name: "another user", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"5678"}} - newIgnCfg.Passwd.Users[0] = tempUser3 - newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) - _, errMsg = reconcilable(oldMcfg, newMcfg) - checkIrreconcilableResults(t, "SSH", errMsg) - // check that we cannot make updates if any other Passwd.User field is changed. tempUser4 := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"5678"}, HomeDir: helpers.StrToPtr("somedir")} newIgnCfg.Passwd.Users[0] = tempUser4 From fc135441996e54340b64dd5e2a8dcbb56bb039b8 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Fri, 17 Mar 2023 09:47:03 -0500 Subject: [PATCH 29/41] wrongfully removed test case --- pkg/daemon/update_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/daemon/update_test.go b/pkg/daemon/update_test.go index a1887d06b4..926ab69a89 100644 --- a/pkg/daemon/update_test.go +++ b/pkg/daemon/update_test.go @@ -373,6 +373,16 @@ func TestReconcilableSSH(t *testing.T) { _, errMsg := reconcilable(oldMcfg, newMcfg) checkReconcilableResults(t, "SSH", errMsg) + // Check that updating User with User that is not core is not supported + tempUser2 := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"1234"}} + oldIgnCfg.Passwd.Users = append(oldIgnCfg.Passwd.Users, tempUser2) + oldMcfg = helpers.CreateMachineConfigFromIgnition(oldIgnCfg) + tempUser3 := ign3types.PasswdUser{Name: "another user", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"5678"}} + newIgnCfg.Passwd.Users[0] = tempUser3 + newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) + _, errMsg = reconcilable(oldMcfg, newMcfg) + checkIrreconcilableResults(t, "SSH", errMsg) + // check that we cannot make updates if any other Passwd.User field is changed. tempUser4 := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"5678"}, HomeDir: helpers.StrToPtr("somedir")} newIgnCfg.Passwd.Users[0] = tempUser4 From 5fcf0e847c877797ff0badbf9dc98461b83a8e1b Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Mon, 20 Mar 2023 10:51:03 -0500 Subject: [PATCH 30/41] removed unit test for causing panic if users is empty --- pkg/daemon/update_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/daemon/update_test.go b/pkg/daemon/update_test.go index 926ab69a89..d7ebf20b09 100644 --- a/pkg/daemon/update_test.go +++ b/pkg/daemon/update_test.go @@ -404,12 +404,6 @@ func TestReconcilableSSH(t *testing.T) { newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) _, errMsg = reconcilable(oldMcfg, newMcfg) checkIrreconcilableResults(t, "SSH", errMsg) - - //check that empty Users does not cause panic - newIgnCfg.Passwd.Users = nil - newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) - _, errMsg = reconcilable(oldMcfg, newMcfg) - checkIrreconcilableResults(t, "SSH", errMsg) } func TestWriteFiles(t *testing.T) { From 5227b030de7af49b8623c2236b73ff58f2c914be Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Fri, 31 Mar 2023 10:53:52 -0500 Subject: [PATCH 31/41] Update pkg/daemon/update.go Co-authored-by: John Kyros <79665180+jkyros@users.noreply.github.com> --- pkg/daemon/update.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index 5ab4be262e..c0e1bd4770 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -831,7 +831,8 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition passwd user section contains unsupported changes: non-core user") } } - if !newEmpty { + // We don't want to panic if the "new" users is empty, and it's still reconcilable because the absence of a user here does not mean "remove the user from the system" + if len(newIgn.Passwd.Users) != 0 { glog.Infof("user data to be verified before ssh update: %v", newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]) if err := verifyUserFields(newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]); err != nil { return nil, err From 3811816a42a3b4df7e1815cef6ad60d46bfb4feb Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Fri, 31 Mar 2023 10:59:07 -0500 Subject: [PATCH 32/41] added back test to ensure that the empty users is reconcilable and removed newEmpty variable --- pkg/daemon/update.go | 3 +-- pkg/daemon/update_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index c0e1bd4770..5c07349c24 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -823,7 +823,6 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition Passwd Groups section contains changes") } if !reflect.DeepEqual(oldIgn.Passwd.Users, newIgn.Passwd.Users) { - newEmpty := len(newIgn.Passwd.Users) == 0 // there is an update to Users, we must verify that it is ONLY making an acceptable // change to the SSHAuthorizedKeys for the user "core" for _, user := range newIgn.Passwd.Users { @@ -831,7 +830,7 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition passwd user section contains unsupported changes: non-core user") } } - // We don't want to panic if the "new" users is empty, and it's still reconcilable because the absence of a user here does not mean "remove the user from the system" + // We don't want to panic if the "new" users is empty, and it's still reconcilable because the absence of a user here does not mean "remove the user from the system" if len(newIgn.Passwd.Users) != 0 { glog.Infof("user data to be verified before ssh update: %v", newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]) if err := verifyUserFields(newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]); err != nil { diff --git a/pkg/daemon/update_test.go b/pkg/daemon/update_test.go index d7ebf20b09..77ae60cab1 100644 --- a/pkg/daemon/update_test.go +++ b/pkg/daemon/update_test.go @@ -404,6 +404,12 @@ func TestReconcilableSSH(t *testing.T) { newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) _, errMsg = reconcilable(oldMcfg, newMcfg) checkIrreconcilableResults(t, "SSH", errMsg) + + //check that empty Users does not cause panic + newIgnCfg.Passwd.Users = nil + newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) + _, errMsg = reconcilable(oldMcfg, newMcfg) + checkReconcilableResults(t, "SSH", errMsg) } func TestWriteFiles(t *testing.T) { From 7930146bc6c31c0e7066604e8b221fddc2dad7f7 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Fri, 31 Mar 2023 11:00:25 -0500 Subject: [PATCH 33/41] oops space --- pkg/daemon/update.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index 5c07349c24..949ddbc96f 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -837,7 +837,6 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, err } } - } } From b81edf3be75f316778d229c573da9879d3cb3f9d Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 25 May 2023 15:45:47 -0500 Subject: [PATCH 34/41] added functionality to clear out password when core user is removed --- pkg/daemon/daemon.go | 2 +- pkg/daemon/update.go | 72 ++++++++++++++++++++++++++++++++++----- pkg/daemon/update_test.go | 5 +-- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index adcb752068..edc9db9ed5 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -1687,7 +1687,7 @@ func (dn *Daemon) updateSSHKeyLocation(cfg *mcfgv1.MachineConfig) error { return fmt.Errorf("ignition failure when updating SSH key location: %w", err) } - if err := dn.updateSSHKeys(ignConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(ignConfig.Passwd.Users, ignConfig.Passwd.Users); err != nil { return fmt.Errorf("could not write SSH keys to new location: %w", err) } diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index 949ddbc96f..e86701bf04 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -546,13 +546,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi } }() - if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { return err } defer func() { if retErr != nil { - if err := dn.updateSSHKeys(oldIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error rolling back SSH keys updates: %w", errs) return @@ -561,13 +561,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi }() // Set password hash - if err := dn.SetPasswordHash(newIgnConfig.Passwd.Users); err != nil { + if err := dn.SetPasswordHash(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { return err } defer func() { if retErr != nil { - if err := dn.SetPasswordHash(oldIgnConfig.Passwd.Users); err != nil { + if err := dn.SetPasswordHash(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error rolling back password hash updates: %w", errs) return @@ -651,13 +651,13 @@ func (dn *Daemon) updateHypershift(oldConfig, newConfig *mcfgv1.MachineConfig, d } }() - if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { return err } defer func() { if retErr != nil { - if err := dn.updateSSHKeys(oldIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error rolling back SSH keys updates: %w", errs) return @@ -1597,9 +1597,26 @@ func (dn *Daemon) atomicallyWriteSSHKey(authKeyPath, keys string) error { } // Set a given PasswdUser's Password Hash -func (dn *Daemon) SetPasswordHash(newUsers []ign3types.PasswdUser) error { +func (dn *Daemon) SetPasswordHash(newUsers []ign3types.PasswdUser, oldUsers []ign3types.PasswdUser) error { // confirm that user exits + glog.Info("checking if absent users need to be disconfigured") + + // Print and log the oldUsers + fmt.Println("Old Users:") + for _, user := range oldUsers { + fmt.Printf("Name: %s\n", user.Name) + } + // glog.Infof("Old Users: %+v", oldUsers) + + // Print and log the newUsers + fmt.Println("New Users:") + for _, user := range newUsers { + fmt.Printf("Name: %s\n", user.Name) + } + // glog.Infof("New Users: %+v", newUsers) + if len(newUsers) == 0 { + deconfigureAbsentUsers(oldUsers, newUsers) return nil } @@ -1637,8 +1654,12 @@ func (dn *Daemon) useNewSSHKeyPath() bool { } // Update a given PasswdUser's SSHKey -func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser) error { +func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser, oldUsers []ign3types.PasswdUser) error { + glog.Info("updating SSH keys") + if len(newUsers) == 0 { + glog.Info("no new users") + deconfigureAbsentUsers(newUsers, oldUsers) return nil } @@ -1689,6 +1710,41 @@ func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser) error { return nil } +func deconfigureAbsentUsers(oldUsers []ign3types.PasswdUser, newUsers []ign3types.PasswdUser) { + glog.Info("checking to deconfigure the absent user") + for _, oldUser := range oldUsers { + if !isUserPresent(oldUser, newUsers) { + glog.Infof("deconfiguring the user %s\n", oldUser.Name) + deconfigureUser(oldUser) + } + } +} + +func isUserPresent(user ign3types.PasswdUser, userList []ign3types.PasswdUser) bool { + glog.Info("checking if user is present") + for _, u := range userList { + if u.Name == user.Name { + return true + } + } + return false +} + +func deconfigureUser(user ign3types.PasswdUser) error { + glog.Info("deconfiguring the absent user") + + // clear out password + pwhash := "" + user.PasswordHash = &pwhash + + if out, err := exec.Command("usermod", "-p", *user.PasswordHash, user.Name).CombinedOutput(); err != nil { + return fmt.Errorf("Failed to change password for %s: %s:%w", user.Name, out, err) + } + + glog.Info("Password has been reset") + return nil +} + // Determines if a file exists by checking for the presence or lack thereof of // an error when stat'ing the file. Returns any other error. func fileExists(path string) (bool, error) { diff --git a/pkg/daemon/update_test.go b/pkg/daemon/update_test.go index 77ae60cab1..1af78bbdbd 100644 --- a/pkg/daemon/update_test.go +++ b/pkg/daemon/update_test.go @@ -502,8 +502,9 @@ func TestUpdateSSHKeys(t *testing.T) { // Set up machineconfigs that are identical except for SSH keys tempUser := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"1234", "4567"}} newIgnCfg := ctrlcommon.NewIgnConfig() + oldIgnConfig := ctrlcommon.NewIgnConfig() newIgnCfg.Passwd.Users = []ign3types.PasswdUser{tempUser} - err := d.updateSSHKeys(newIgnCfg.Passwd.Users) + err := d.updateSSHKeys(newIgnCfg.Passwd.Users, oldIgnConfig.Passwd.Users) if err != nil { t.Errorf("Expected no error. Got %s.", err) @@ -512,7 +513,7 @@ func TestUpdateSSHKeys(t *testing.T) { // if Users is empty, nothing should happen and no error should ever be generated newIgnCfg2 := ctrlcommon.NewIgnConfig() newIgnCfg2.Passwd.Users = []ign3types.PasswdUser{} - err = d.updateSSHKeys(newIgnCfg2.Passwd.Users) + err = d.updateSSHKeys(newIgnCfg2.Passwd.Users, oldIgnConfig.Passwd.Users) if err != nil { t.Errorf("Expected no error. Got: %s", err) } From 3800dea5ee36ed63cc5277c508c864108738f5b5 Mon Sep 17 00:00:00 2001 From: Dalia Khater <74260788+dkhater-redhat@users.noreply.github.com> Date: Thu, 25 May 2023 16:16:54 -0500 Subject: [PATCH 35/41] making so that updateSSHKeys runs in all cases --- pkg/daemon/update.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index e86701bf04..b3b4c1ec2d 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -1606,19 +1606,15 @@ func (dn *Daemon) SetPasswordHash(newUsers []ign3types.PasswdUser, oldUsers []ig for _, user := range oldUsers { fmt.Printf("Name: %s\n", user.Name) } - // glog.Infof("Old Users: %+v", oldUsers) // Print and log the newUsers fmt.Println("New Users:") for _, user := range newUsers { fmt.Printf("Name: %s\n", user.Name) } - // glog.Infof("New Users: %+v", newUsers) - if len(newUsers) == 0 { - deconfigureAbsentUsers(oldUsers, newUsers) - return nil - } + // checking if old users need to be deconfigured + deconfigureAbsentUsers(oldUsers, newUsers) var uErr user.UnknownUserError switch _, err := user.Lookup(constants.CoreUserName); { @@ -1657,11 +1653,8 @@ func (dn *Daemon) useNewSSHKeyPath() bool { func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser, oldUsers []ign3types.PasswdUser) error { glog.Info("updating SSH keys") - if len(newUsers) == 0 { - glog.Info("no new users") - deconfigureAbsentUsers(newUsers, oldUsers) - return nil - } + // Checking to see if absent users need to be deconfigured + deconfigureAbsentUsers(newUsers, oldUsers) var uErr user.UnknownUserError switch _, err := user.Lookup(constants.CoreUserName); { @@ -1733,7 +1726,7 @@ func isUserPresent(user ign3types.PasswdUser, userList []ign3types.PasswdUser) b func deconfigureUser(user ign3types.PasswdUser) error { glog.Info("deconfiguring the absent user") - // clear out password + // clear out password and sshkey pwhash := "" user.PasswordHash = &pwhash @@ -1741,7 +1734,7 @@ func deconfigureUser(user ign3types.PasswdUser) error { return fmt.Errorf("Failed to change password for %s: %s:%w", user.Name, out, err) } - glog.Info("Password has been reset") + glog.Info("Password and SSH Key have been reset") return nil } From 63d53a504bb70fd73952c6ef66fb359814619077 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Tue, 20 Jun 2023 12:52:43 -0500 Subject: [PATCH 36/41] removed on cluster build key --- pkg/operator/sync.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 6753b00170..d00f5158cd 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -44,7 +44,6 @@ import ( const ( requiredForUpgradeMachineConfigPoolLabelKey = "operator.machineconfiguration.openshift.io/required-for-upgrade" - onClusterBuildPoolLabelKey = "on-cluster-build" ) var ( @@ -725,7 +724,7 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { } func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { - glog.Infof("Checking for On Cluster Build Tag") + glog.Infof("Checking for an 'on-cluster-build' tag") pools, err := optr.mcpLister.List(labels.Everything()) if err != nil { @@ -743,7 +742,8 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { } func startBuildControllerPod() { - fmt.Printf("hello this starts the build controller pod\n") + fmt.Printf("Starting Build Controller Pod\n") + } func (optr *Operator) syncMachineConfigDaemon(config *renderConfig) error { From d40072aa48d6e17f046e202b56b563f0fe0fc15a Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Tue, 20 Jun 2023 13:31:33 -0500 Subject: [PATCH 37/41] testing functionality of pausing node controller --- pkg/controller/node/node_controller.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/controller/node/node_controller.go b/pkg/controller/node/node_controller.go index 4df7ee1dbb..f35ed2585a 100644 --- a/pkg/controller/node/node_controller.go +++ b/pkg/controller/node/node_controller.go @@ -1189,9 +1189,11 @@ func shouldApplyConfigToPool(pool *mcfgv1.MachineConfigPool) bool { func updateCandidateMachines(pool *mcfgv1.MachineConfigPool, candidates []*corev1.Node, capacity uint) error { if !shouldApplyConfigToPool(pool) { // Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything. + fmt.Println("Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything.") return nil } // Continue with the rest of the update logic for the pool + fmt.Println("Continue with the rest of the update logic for the pool") return nil } From 8bb59fb0640ff6e446c3fd45020014e4c71fe4fb Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Tue, 20 Jun 2023 14:02:26 -0500 Subject: [PATCH 38/41] added comments for clarity --- pkg/controller/node/node_controller.go | 5 +++-- pkg/operator/sync.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/controller/node/node_controller.go b/pkg/controller/node/node_controller.go index f35ed2585a..7a0dc1a429 100644 --- a/pkg/controller/node/node_controller.go +++ b/pkg/controller/node/node_controller.go @@ -1181,6 +1181,7 @@ func getErrorString(err error) string { // If a pool is labeled with 'LayeringEnabledPoolLabel', it returns false indicating that no action should be taken. // Otherwise, it returns true indicating that the node-controller can proceed with applying configurations to the pool. func shouldApplyConfigToPool(pool *mcfgv1.MachineConfigPool) bool { + glog.Info("Checking if node-controller should apply configurations to on-cluster-build pool") labels := pool.GetLabels() _, exists := labels[LayeringEnabledPoolLabel] return !exists @@ -1189,11 +1190,11 @@ func shouldApplyConfigToPool(pool *mcfgv1.MachineConfigPool) bool { func updateCandidateMachines(pool *mcfgv1.MachineConfigPool, candidates []*corev1.Node, capacity uint) error { if !shouldApplyConfigToPool(pool) { // Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything. - fmt.Println("Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything.") + glog.Info("Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything.") return nil } // Continue with the rest of the update logic for the pool - fmt.Println("Continue with the rest of the update logic for the pool") + glog.Info("Continue with the rest of the update logic for the pool") return nil } diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index d00f5158cd..87b4231b26 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -731,10 +731,11 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { glog.Fatal(err) } for _, pool := range pools { - glog.Infof("Pool found: %s \n", pool.Name) if pool.Name == "on-cluster-build" { fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) startBuildControllerPod() + } else { + fmt.Printf("Pool on-cluster-build not found\n") } } @@ -743,7 +744,7 @@ func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { func startBuildControllerPod() { fmt.Printf("Starting Build Controller Pod\n") - + // add logic to start build controller pod } func (optr *Operator) syncMachineConfigDaemon(config *renderConfig) error { From 0bc705fc43ee6cd526c01cd1977e43443a8952e2 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Tue, 20 Jun 2023 14:46:36 -0500 Subject: [PATCH 39/41] seeing if node controller sees new mcp --- pkg/controller/node/node_controller.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/controller/node/node_controller.go b/pkg/controller/node/node_controller.go index 7a0dc1a429..f4b110c1ef 100644 --- a/pkg/controller/node/node_controller.go +++ b/pkg/controller/node/node_controller.go @@ -600,6 +600,9 @@ func (ctrl *Controller) getPoolsForNode(node *corev1.Node) ([]*mcfgv1.MachineCon } pools = append(pools, p) + + fmt.Printf("Found MachineConfigPool: %s\n", p.Name) + } if len(pools) == 0 { From 556d5e94e915fbd1b564b56e59094ab80a150360 Mon Sep 17 00:00:00 2001 From: Dalia Khater Date: Mon, 26 Jun 2023 12:45:22 +0200 Subject: [PATCH 40/41] rework Machine OS Builder startup logic --- cmd/machine-os-builder/main.go | 1 + manifests/machineosbuilder/deployment.yaml | 8 +- pkg/operator/sync.go | 125 +++++++++++++++++---- 3 files changed, 104 insertions(+), 30 deletions(-) diff --git a/cmd/machine-os-builder/main.go b/cmd/machine-os-builder/main.go index 4d19bb323f..4a44141684 100644 --- a/cmd/machine-os-builder/main.go +++ b/cmd/machine-os-builder/main.go @@ -23,4 +23,5 @@ func init() { func main() { fmt.Println("Hello, World!") + select{} } diff --git a/manifests/machineosbuilder/deployment.yaml b/manifests/machineosbuilder/deployment.yaml index 06cbd4c6e4..1fa5a8b56d 100644 --- a/manifests/machineosbuilder/deployment.yaml +++ b/manifests/machineosbuilder/deployment.yaml @@ -15,9 +15,5 @@ spec: spec: containers: - name: machine-os-builder - image: openshift/hello-openshift:latest - ports: - - containerPort: 80 - args: - - "start" - - "--resourcelock-namespace={{.TargetNamespace}}" + image: {{.Images.MachineConfigOperator}} + command: ["/usr/bin/machine-os-builder"] diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index 87b4231b26..be1e14a95a 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -23,6 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/selection" kubeErrs "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" @@ -40,6 +41,8 @@ import ( daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants" "github.com/openshift/machine-config-operator/pkg/server" "github.com/openshift/machine-config-operator/pkg/version" + + autoscalingv1 "k8s.io/api/autoscaling/v1" ) const ( @@ -677,7 +680,10 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { } func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { - glog.Infof("Performing Machine OS Builder sync") + glog.V(4).Info("Machine OS Builder sync started") + defer func() { + glog.V(4).Info("Machine OS Builder sync complete") + }() paths := manifestPaths{ clusterRoles: []string{ @@ -695,56 +701,127 @@ func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { mobServiceAccountManifestPath, }, } + + // It's probably fine to leave these around if we don't have an opted-in + // pool, since they don't consume any resources. if err := optr.applyManifests(config, paths); err != nil { return fmt.Errorf("failed to apply machine os builder manifests: %w", err) } mobBytes, err := renderAsset(config, "manifests/machineosbuilder/deployment.yaml") if err != nil { - return err + return fmt.Errorf("could not render Machine OS Builder deployment asset: %w", err) } + mob := resourceread.ReadDeploymentV1OrDie(mobBytes) - _, updated, err := mcoResourceApply.ApplyDeployment(optr.kubeClient.AppsV1(), mob) + return optr.reconcileMachineOSBuilder(mob) +} + +// Determines if the Machine OS Builder deployment is in the correct state +// based upon whether we have opted-in pools or not. +func (optr *Operator) reconcileMachineOSBuilder(mob *appsv1.Deployment) error { + // First, check if we have any MachineConfigPools opted in. + layeredMCPs, err := optr.getLayeredMachineConfigPools() if err != nil { - return err + return fmt.Errorf("could not get layered MachineConfigPools: %w", err) } - if updated { - if err := optr.waitForDeploymentRollout(mob); err != nil { - return err + + isRunning, err := optr.isMachineOSBuilderRunning(mob) + // An unknown error occurred. Bail out here. + if err != nil && !apierrors.IsNotFound(err) { + return fmt.Errorf("could not determine if Machine OS Builder is running: %w", err) + } + + // If the deployment does not exist and we do not have any opted-in pools, we + // should create the deployment with zero replicas so that it exists. + if apierrors.IsNotFound(err) && len(layeredMCPs) == 0 { + glog.Infof("Created Machine OS Builder deployment") + return optr.updateMachineOSBuilderDeployment(mob, 0) + } + + // If we have opted-in pools and the Machine OS Builder deployment is not + // running, scale it up. + if len(layeredMCPs) != 0 && !isRunning { + layeredMCPNames := []string{} + for _, mcp := range layeredMCPs { + layeredMCPNames = append(layeredMCPNames, mcp.Name) } + glog.Infof("Starting Machine OS Builder pod because MachineConfigPool(s) opted into layering: %v", layeredMCPNames) + return optr.updateMachineOSBuilderDeployment(mob, 1) } - err = optr.checkForOnClusterBuild(config) - if err != nil { - return err + // If we do not have opted-in pools and the Machine OS Builder deployment is + // running, scale it down. + if len(layeredMCPs) == 0 && isRunning { + glog.Infof("Shutting down Machine OS Builder pod because no MachineConfigPool(s) opted into layering") + return optr.updateMachineOSBuilderDeployment(mob, 0) } - return optr.syncControllerConfig(config) + // No-op if everything is in the desired state. + return nil } -func (optr *Operator) checkForOnClusterBuild(config *renderConfig) error { - glog.Infof("Checking for an 'on-cluster-build' tag") +// Determines if the Machine OS Builder is running based upon how many replicas +// we have. If an error is encountered, it is assumed that no Deployments are +// running. +func (optr *Operator) isMachineOSBuilderRunning(mob *appsv1.Deployment) (bool, error) { + apiMob, err := optr.deployLister.Deployments(ctrlcommon.MCONamespace).Get(mob.Name) - pools, err := optr.mcpLister.List(labels.Everything()) + if err == nil && *apiMob.Spec.Replicas != 0 { + return true, nil + } + + return false, err +} + +// Updates the Machine OS Builder Deployment, creating it if it does not exist. +func (optr *Operator) updateMachineOSBuilderDeployment(mob *appsv1.Deployment, replicas int32) error { + _, updated, err := mcoResourceApply.ApplyDeployment(optr.kubeClient.AppsV1(), mob) if err != nil { - glog.Fatal(err) + return fmt.Errorf("could not apply Machine OS Builder deployment: %w", err) } - for _, pool := range pools { - if pool.Name == "on-cluster-build" { - fmt.Printf("Pool %s is labeled with 'on-cluster-build'. Starting the build controller pod.\n", pool.Name) - startBuildControllerPod() - } else { - fmt.Printf("Pool on-cluster-build not found\n") + + scale := &autoscalingv1.Scale{ + ObjectMeta: mob.ObjectMeta, + Spec: autoscalingv1.ScaleSpec{ + Replicas: replicas, + }, + } + + _, err = optr.kubeClient.AppsV1().Deployments(ctrlcommon.MCONamespace).UpdateScale(context.TODO(), mob.Name, scale, metav1.UpdateOptions{}) + if err != nil { + return fmt.Errorf("could not scale Machine OS Builder: %w", err) + } + + if updated { + if err := optr.waitForDeploymentRollout(mob); err != nil { + return fmt.Errorf("could not wait for Machine OS Builder deployment rollout: %w", err) } } return nil } -func startBuildControllerPod() { - fmt.Printf("Starting Build Controller Pod\n") - // add logic to start build controller pod +// Returns a list of MachineConfigPools which have opted in to layering. +// Returns an empty list if none have opted in. +func (optr *Operator) getLayeredMachineConfigPools() ([]*mcfgv1.MachineConfigPool, error) { + // TODO: Once https://github.com/openshift/machine-config-operator/pull/3731 + // lands, change this to consume ctrlcommon.LayeringEnabledPoolLabel instead + // of having this hard-coded here. + layeringEnabledPoolLabel := "machineconfiguration.openshift.io/layering-enabled" + requirement, err := labels.NewRequirement(layeringEnabledPoolLabel, selection.Exists, []string{}) + if err != nil { + return []*mcfgv1.MachineConfigPool{}, err + } + + selector := labels.NewSelector().Add(*requirement) + pools, err := optr.mcpLister.List(selector) + if err != nil { + return []*mcfgv1.MachineConfigPool{}, err + } + + return pools, nil } func (optr *Operator) syncMachineConfigDaemon(config *renderConfig) error { From aa71b7f81ca9274dc5f383af773184af8514d18d Mon Sep 17 00:00:00 2001 From: Ines Qian Date: Fri, 23 Jun 2023 16:39:29 -0400 Subject: [PATCH 41/41] Move all log functions to klog Removed ssh bug, tidied up code, added labels, removed glog --- cmd/apiserver-watcher/main.go | 5 +- cmd/apiserver-watcher/run.go | 18 +- cmd/common/helpers.go | 12 +- cmd/machine-config-controller/bootstrap.go | 8 +- cmd/machine-config-controller/start.go | 6 +- .../firstboot_complete_machineconfig.go | 6 +- cmd/machine-config-daemon/start.go | 38 +- cmd/machine-config-operator/bootstrap.go | 14 +- cmd/machine-config-operator/start.go | 10 +- cmd/machine-config-server/bootstrap.go | 6 +- cmd/machine-config-server/start.go | 6 +- cmd/machine-os-builder/start.go | 6 +- go.mod | 3 +- go.sum | 2 - hack/cluster-push.sh | 9 +- internal/clients/builder.go | 6 +- pkg/controller/bootstrap/bootstrap.go | 6 +- pkg/controller/common/constants.go | 4 + pkg/controller/common/controller_context.go | 3 +- pkg/controller/common/helpers.go | 28 +- pkg/controller/common/metrics.go | 14 +- .../container_runtime_config_bootstrap.go | 5 +- .../container_runtime_config_controller.go | 52 +- ...ontainer_runtime_config_controller_test.go | 14 +- .../container-runtime-config/helpers.go | 14 +- pkg/controller/drain/drain_controller.go | 40 +- .../kubelet_config_controller.go | 36 +- .../kubelet_config_controller_test.go | 8 +- .../kubelet-config/kubelet_config_features.go | 14 +- .../kubelet-config/kubelet_config_nodes.go | 28 +- pkg/controller/node/node_controller.go | 93 +- pkg/controller/node/status.go | 8 +- pkg/controller/render/render_controller.go | 54 +- pkg/controller/template/render.go | 15 +- .../template/template_controller.go | 51 +- pkg/daemon/certificate_writer.go | 15 +- pkg/daemon/config_drift_monitor.go | 14 +- pkg/daemon/coreos.go | 10 +- pkg/daemon/daemon.go | 222 ++-- pkg/daemon/drain.go | 26 +- pkg/daemon/file_writers.go | 30 +- pkg/daemon/kernelargs.go | 14 +- pkg/daemon/node.go | 8 +- pkg/daemon/on_disk_validation.go | 6 +- pkg/daemon/pivot/utils/run.go | 6 +- pkg/daemon/rpm-ostree.go | 26 +- pkg/daemon/update.go | 206 ++- pkg/daemon/update_test.go | 7 +- pkg/daemon/writer.go | 16 +- pkg/operator/bootstrap.go | 6 +- pkg/operator/operator.go | 24 +- pkg/operator/render.go | 4 +- pkg/operator/status.go | 14 +- pkg/operator/sync.go | 45 +- pkg/server/api.go | 26 +- pkg/server/bootstrap_server.go | 10 +- test/e2e/mco_test.go | 6 +- test/framework/clientset.go | 6 +- vendor/github.com/golang/glog/LICENSE | 191 --- vendor/github.com/golang/glog/README.md | 36 - vendor/github.com/golang/glog/glog.go | 1180 ----------------- vendor/github.com/golang/glog/glog_file.go | 124 -- vendor/modules.txt | 3 +- 63 files changed, 669 insertions(+), 2254 deletions(-) delete mode 100644 vendor/github.com/golang/glog/LICENSE delete mode 100644 vendor/github.com/golang/glog/README.md delete mode 100644 vendor/github.com/golang/glog/glog.go delete mode 100644 vendor/github.com/golang/glog/glog_file.go diff --git a/cmd/apiserver-watcher/main.go b/cmd/apiserver-watcher/main.go index 163e09cf98..b7a31ca6a9 100644 --- a/cmd/apiserver-watcher/main.go +++ b/cmd/apiserver-watcher/main.go @@ -3,7 +3,8 @@ package main import ( "flag" - "github.com/golang/glog" + "k8s.io/klog/v2" + "github.com/spf13/cobra" ) @@ -27,6 +28,6 @@ func init() { func main() { if err := rootCmd.Execute(); err != nil { - glog.Exitf("Error executing %s: %v", componentName, err) + klog.Exitf("Error executing %s: %v", componentName, err) } } diff --git a/cmd/apiserver-watcher/run.go b/cmd/apiserver-watcher/run.go index a5651af28a..6bfe5d2260 100644 --- a/cmd/apiserver-watcher/run.go +++ b/cmd/apiserver-watcher/run.go @@ -15,8 +15,8 @@ import ( health "github.com/InVisionApp/go-health" "github.com/InVisionApp/go-health/checkers" - "github.com/golang/glog" "github.com/spf13/cobra" + "k8s.io/klog/v2" "github.com/openshift/machine-config-operator/pkg/version" ) @@ -54,7 +54,7 @@ func runRunCmd(cmd *cobra.Command, args []string) error { flag.Parse() // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) uri, err := url.Parse(runOpts.healthCheckURL) if err != nil { @@ -117,9 +117,9 @@ func runRunCmd(cmd *cobra.Command, args []string) error { signal.Notify(c, os.Interrupt) go func() { for sig := range c { - glog.Infof("Signal %s received: treating service as down", sig) + klog.Infof("Signal %s received: treating service as down", sig) if err := handler.onFailure(); err != nil { - glog.Infof("Failed to mark service down on signal: %s", err) + klog.Infof("Failed to mark service down on signal: %s", err) } os.Exit(0) } @@ -147,7 +147,7 @@ func newHandler(uri *url.URL) (*handler, error) { h := handler{ vips: addrs, } - glog.Infof("Using VIPs %v", h.vips) + klog.Infof("Using VIPs %v", h.vips) return &h, nil } @@ -157,7 +157,7 @@ func (h *handler) onFailure() error { if err := writeVipStateFile(vip, "down"); err != nil { return err } - glog.Infof("healthcheck failed, created downfile %s.down", vip) + klog.Infof("healthcheck failed, created downfile %s.down", vip) if err := removeVipStateFile(vip, "up"); err != nil { return err } @@ -171,7 +171,7 @@ func (h *handler) onSuccess() error { if err := removeVipStateFile(vip, "down"); err != nil { return err } - glog.Infof("healthcheck succeeded, removed downfile %s.down", vip) + klog.Infof("healthcheck succeeded, removed downfile %s.down", vip) if err := writeVipStateFile(vip, "up"); err != nil { return err } @@ -246,7 +246,7 @@ func (sl *healthTracker) OnComplete(state *health.State) { sl.succeeded++ if sl.succeeded >= sl.SuccessThreshold { if sl.state != succeededTrackerState { - glog.Info("Running OnSuccess trigger") + klog.Info("Running OnSuccess trigger") if err := sl.OnSuccess(); err != nil { sl.ErrCh <- err } @@ -258,7 +258,7 @@ func (sl *healthTracker) OnComplete(state *health.State) { sl.failed++ if sl.failed >= sl.FailureThreshold { if sl.state != failedTrackerState { - glog.Info("Running OnFailure trigger") + klog.Info("Running OnFailure trigger") if err := sl.OnFailure(); err != nil { sl.ErrCh <- err } diff --git a/cmd/common/helpers.go b/cmd/common/helpers.go index 032842598d..b1226e260b 100644 --- a/cmd/common/helpers.go +++ b/cmd/common/helpers.go @@ -5,13 +5,13 @@ import ( "os/signal" "syscall" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/internal/clients" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/tools/leaderelection/resourcelock" "k8s.io/client-go/tools/record" + "k8s.io/klog/v2" "context" @@ -31,7 +31,7 @@ func CreateResourceLock(cb *clients.Builder, componentNamespace, componentName s id, err := os.Hostname() if err != nil { - glog.Fatalf("error creating lock: %v", err) + klog.Fatalf("error creating lock: %v", err) } // add a uniquifier so that two processes on the same host don't accidentally both become active @@ -73,7 +73,7 @@ func GetLeaderElectionConfig(restcfg *rest.Config) configv1.LeaderElection { return leaderelection.LeaderElectionSNOConfig(defaultLeaderElection) } } else { - glog.Warningf("unable to get cluster infrastructure status, using HA cluster values for leader election: %v", err) + klog.Warningf("unable to get cluster infrastructure status, using HA cluster values for leader election: %v", err) } return defaultLeaderElection @@ -90,11 +90,11 @@ func SignalHandler(runCancel context.CancelFunc) { // catch SIGINT and SIGTERM signal.Notify(ch, os.Interrupt, syscall.SIGTERM) sig := <-ch - glog.Infof("Shutting down due to: %s", sig) + klog.Infof("Shutting down due to: %s", sig) // if we're shutting down, cancel the context so everything else will stop runCancel() - glog.Infof("Context cancelled") + klog.Infof("Context cancelled") sig = <-ch - glog.Fatalf("Received shutdown signal twice, exiting: %s", sig) + klog.Fatalf("Received shutdown signal twice, exiting: %s", sig) } diff --git a/cmd/machine-config-controller/bootstrap.go b/cmd/machine-config-controller/bootstrap.go index 8d9384f320..f0b39688c5 100644 --- a/cmd/machine-config-controller/bootstrap.go +++ b/cmd/machine-config-controller/bootstrap.go @@ -3,8 +3,8 @@ package main import ( "flag" - "github.com/golang/glog" "github.com/spf13/cobra" + "k8s.io/klog/v2" "github.com/openshift/machine-config-operator/pkg/controller/bootstrap" "github.com/openshift/machine-config-operator/pkg/version" @@ -37,13 +37,13 @@ func runbootstrapCmd(cmd *cobra.Command, args []string) { flag.Parse() // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) if bootstrapOpts.manifestsDir == "" || bootstrapOpts.destinationDir == "" { - glog.Fatalf("--dest-dir or --manifest-dir not set") + klog.Fatalf("--dest-dir or --manifest-dir not set") } if err := bootstrap.New(rootOpts.templates, bootstrapOpts.manifestsDir, bootstrapOpts.pullSecretFile).Run(bootstrapOpts.destinationDir); err != nil { - glog.Fatalf("error running MCC[BOOTSTRAP]: %v", err) + klog.Fatalf("error running MCC[BOOTSTRAP]: %v", err) } } diff --git a/cmd/machine-config-controller/start.go b/cmd/machine-config-controller/start.go index 6d9c0c232c..aaa5238db9 100644 --- a/cmd/machine-config-controller/start.go +++ b/cmd/machine-config-controller/start.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/golang/glog" + "github.com/openshift/library-go/pkg/operator/configobserver/featuregates" "github.com/openshift/machine-config-operator/cmd/common" "github.com/openshift/machine-config-operator/internal/clients" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -54,7 +54,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { runContext, runCancel := context.WithCancel(context.Background()) // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) cb, err := clients.NewBuilder(startOpts.kubeconfig) if err != nil { @@ -105,7 +105,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { Callbacks: leaderelection.LeaderCallbacks{ OnStartedLeading: run, OnStoppedLeading: func() { - glog.Infof("Stopped leading. Terminating.") + klog.Infof("Stopped leading. Terminating.") os.Exit(0) }, }, diff --git a/cmd/machine-config-daemon/firstboot_complete_machineconfig.go b/cmd/machine-config-daemon/firstboot_complete_machineconfig.go index e5ee734b6a..41b9748baa 100644 --- a/cmd/machine-config-daemon/firstboot_complete_machineconfig.go +++ b/cmd/machine-config-daemon/firstboot_complete_machineconfig.go @@ -5,10 +5,10 @@ import ( "fmt" "time" - "github.com/golang/glog" daemon "github.com/openshift/machine-config-operator/pkg/daemon" "github.com/spf13/cobra" "github.com/spf13/pflag" + "k8s.io/klog/v2" ) var firstbootCompleteMachineconfig = &cobra.Command{ @@ -60,8 +60,8 @@ func executeFirstbootCompleteMachineConfig(cmd *cobra.Command, args []string) { for { err := runFirstBootCompleteMachineConfig(cmd, args) if err != nil { - glog.Warningf("error: %v\n", err) - glog.Info("Sleeping 1 minute for retry") + klog.Warningf("error: %v\n", err) + klog.Info("Sleeping 1 minute for retry") time.Sleep(time.Minute) } else { break diff --git a/cmd/machine-config-daemon/start.go b/cmd/machine-config-daemon/start.go index 919858888b..0f229ce338 100644 --- a/cmd/machine-config-daemon/start.go +++ b/cmd/machine-config-daemon/start.go @@ -13,13 +13,13 @@ import ( "github.com/google/renameio" "k8s.io/client-go/tools/clientcmd" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/internal/clients" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/daemon" daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants" "github.com/openshift/machine-config-operator/pkg/version" "github.com/spf13/cobra" + "k8s.io/klog/v2" ) var ( @@ -82,7 +82,7 @@ func selfCopyToHost() error { if err := t.CloseAtomicallyReplace(); err != nil { return err } - glog.Infof("Copied self to /run/bin/machine-config-daemon on host") + klog.Infof("Copied self to /run/bin/machine-config-daemon on host") return nil } @@ -90,10 +90,10 @@ func runStartCmd(cmd *cobra.Command, args []string) { flag.Set("logtostderr", "true") flag.Parse() - glog.V(2).Infof("Options parsed: %+v", startOpts) + klog.V(2).Infof("Options parsed: %+v", startOpts) // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) // See https://github.com/coreos/rpm-ostree/pull/1880 os.Setenv("RPMOSTREE_CLIENT_ID", "machine-config-operator") @@ -102,24 +102,24 @@ func runStartCmd(cmd *cobra.Command, args []string) { if !onceFromMode { // in the daemon case if err := daemon.PrepareNamespace(startOpts.rootMount); err != nil { - glog.Fatalf("Binding pod mounts: %+v", err) + klog.Fatalf("Binding pod mounts: %+v", err) } } - glog.Infof(`Calling chroot("%s")`, startOpts.rootMount) + klog.Infof(`Calling chroot("%s")`, startOpts.rootMount) if err := syscall.Chroot(startOpts.rootMount); err != nil { - glog.Fatalf("Unable to chroot to %s: %s", startOpts.rootMount, err) + klog.Fatalf("Unable to chroot to %s: %s", startOpts.rootMount, err) } - glog.V(2).Infof("Moving to / inside the chroot") + klog.V(2).Infof("Moving to / inside the chroot") if err := os.Chdir("/"); err != nil { - glog.Fatalf("Unable to change directory to /: %s", err) + klog.Fatalf("Unable to change directory to /: %s", err) } if startOpts.nodeName == "" { name, ok := os.LookupEnv("NODE_NAME") if !ok || name == "" { - glog.Fatalf("node-name is required") + klog.Fatalf("node-name is required") } startOpts.nodeName = name } @@ -134,7 +134,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { exitCh, ) if err != nil { - glog.Fatalf("Failed to initialize single run daemon: %v", err) + klog.Fatalf("Failed to initialize single run daemon: %v", err) } // If we are asked to run once and it's a valid file system path use @@ -142,7 +142,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { if startOpts.onceFrom != "" { err = dn.RunOnceFrom(startOpts.onceFrom, startOpts.skipReboot) if err != nil { - glog.Fatalf("%v", err) + klog.Fatalf("%v", err) } return } @@ -150,37 +150,37 @@ func runStartCmd(cmd *cobra.Command, args []string) { // In the cluster case, for now we copy our binary out to the host // for SELinux reasons, see https://bugzilla.redhat.com/show_bug.cgi?id=1839065 if err := selfCopyToHost(); err != nil { - glog.Fatalf("%v", fmt.Errorf("copying self to host: %w", err)) + klog.Fatalf("%v", fmt.Errorf("copying self to host: %w", err)) return } // Use kubelet kubeconfig file to get the URL to kube-api-server kubeconfig, err := clientcmd.LoadFromFile("/etc/kubernetes/kubeconfig") if err != nil { - glog.Fatalf("failed to load kubelet kubeconfig: %v", err) + klog.Fatalf("failed to load kubelet kubeconfig: %v", err) } clusterName := kubeconfig.Contexts[kubeconfig.CurrentContext].Cluster apiURL := kubeconfig.Clusters[clusterName].Server url, err := url.Parse(apiURL) if err != nil { - glog.Fatalf("failed to parse api url from kubelet kubeconfig: %v", err) + klog.Fatalf("failed to parse api url from kubelet kubeconfig: %v", err) } // The kubernetes in-cluster functions don't let you override the apiserver // directly; gotta "pass" it via environment vars. - glog.Infof("overriding kubernetes api to %s", apiURL) + klog.Infof("overriding kubernetes api to %s", apiURL) os.Setenv("KUBERNETES_SERVICE_HOST", url.Hostname()) os.Setenv("KUBERNETES_SERVICE_PORT", url.Port()) cb, err := clients.NewBuilder(startOpts.kubeconfig) if err != nil { - glog.Fatalf("Failed to initialize ClientBuilder: %v", err) + klog.Fatalf("Failed to initialize ClientBuilder: %v", err) } kubeClient, err := cb.KubeClient(componentName) if err != nil { - glog.Fatalf("Cannot initialize kubeClient: %v", err) + klog.Fatalf("Cannot initialize kubeClient: %v", err) } // This channel is used to ensure all spawned goroutines exit when we exit. @@ -225,7 +225,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { startOpts.kubeletHealthzEndpoint, ) if err != nil { - glog.Fatalf("Failed to initialize: %v", err) + klog.Fatalf("Failed to initialize: %v", err) } ctx.KubeInformerFactory.Start(stopCh) diff --git a/cmd/machine-config-operator/bootstrap.go b/cmd/machine-config-operator/bootstrap.go index 29d619c3c5..a8fb440238 100644 --- a/cmd/machine-config-operator/bootstrap.go +++ b/cmd/machine-config-operator/bootstrap.go @@ -5,8 +5,8 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/spf13/cobra" + "k8s.io/klog/v2" imagev1 "github.com/openshift/api/image/v1" "github.com/openshift/library-go/pkg/operator/resource/resourceread" @@ -104,7 +104,7 @@ func findImage(stream *imagev1.ImageStream, name string) (string, error) { func findImageOrDie(stream *imagev1.ImageStream, name string) string { img, err := findImage(stream, name) if err != nil { - glog.Fatalf("Failed to find %s in image references", name) + klog.Fatalf("Failed to find %s in image references", name) } return img } @@ -114,7 +114,7 @@ func runBootstrapCmd(cmd *cobra.Command, args []string) { flag.Parse() // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) baseOSContainerImageTag := "rhel-coreos" if version.IsFCOS() { @@ -126,7 +126,7 @@ func runBootstrapCmd(cmd *cobra.Command, args []string) { if bootstrapOpts.imageReferences != "" { imageRefData, err := os.ReadFile(bootstrapOpts.imageReferences) if err != nil { - glog.Fatalf("failed to read %s: %v", bootstrapOpts.imageReferences, err) + klog.Fatalf("failed to read %s: %v", bootstrapOpts.imageReferences, err) } imgstream := resourceread.ReadImageStreamV1OrDie(imageRefData) @@ -143,11 +143,11 @@ func runBootstrapCmd(cmd *cobra.Command, args []string) { bootstrapOpts.haproxyImage = findImageOrDie(imgstream, "haproxy-router") bootstrapOpts.baseOSContainerImage, err = findImage(imgstream, baseOSContainerImageTag) if err != nil { - glog.Warningf("Base OS container not found: %s", err) + klog.Warningf("Base OS container not found: %s", err) } bootstrapOpts.baseOSExtensionsContainerImage, err = findImage(imgstream, fmt.Sprintf("%s-extensions", baseOSContainerImageTag)) if err != nil { - glog.Warningf("Base OS extensions container not found: %s", err) + klog.Warningf("Base OS extensions container not found: %s", err) } } @@ -185,6 +185,6 @@ func runBootstrapCmd(cmd *cobra.Command, args []string) { bootstrapOpts.destinationDir, bootstrapOpts.releaseImage, ); err != nil { - glog.Fatalf("error rendering bootstrap manifests: %v", err) + klog.Fatalf("error rendering bootstrap manifests: %v", err) } } diff --git a/cmd/machine-config-operator/start.go b/cmd/machine-config-operator/start.go index 93b729753b..afc5ac91ff 100644 --- a/cmd/machine-config-operator/start.go +++ b/cmd/machine-config-operator/start.go @@ -5,7 +5,6 @@ import ( "flag" "os" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/cmd/common" "github.com/openshift/machine-config-operator/internal/clients" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -13,6 +12,7 @@ import ( "github.com/openshift/machine-config-operator/pkg/version" "github.com/spf13/cobra" "k8s.io/client-go/tools/leaderelection" + "k8s.io/klog/v2" ) var ( @@ -46,15 +46,15 @@ func runStartCmd(cmd *cobra.Command, args []string) { runContext, runCancel := context.WithCancel(context.Background()) // To help debugging, immediately log version - glog.Infof("Version: %s (Raw: %s, Hash: %s)", version.ReleaseVersion, version.Raw, version.Hash) + klog.Infof("Version: %s (Raw: %s, Hash: %s)", version.ReleaseVersion, version.Raw, version.Hash) if startOpts.imagesFile == "" { - glog.Fatal("--images-json cannot be empty") + klog.Fatal("--images-json cannot be empty") } cb, err := clients.NewBuilder(startOpts.kubeconfig) if err != nil { - glog.Fatalf("error creating clients: %v", err) + klog.Fatalf("error creating clients: %v", err) } stopCh := make(chan struct{}) @@ -121,7 +121,7 @@ func runStartCmd(cmd *cobra.Command, args []string) { Callbacks: leaderelection.LeaderCallbacks{ OnStartedLeading: run, OnStoppedLeading: func() { - glog.Info("Stopped leading. Terminating.") + klog.Info("Stopped leading. Terminating.") os.Exit(0) }, }, diff --git a/cmd/machine-config-server/bootstrap.go b/cmd/machine-config-server/bootstrap.go index 5565610300..f01f8e50b9 100644 --- a/cmd/machine-config-server/bootstrap.go +++ b/cmd/machine-config-server/bootstrap.go @@ -3,10 +3,10 @@ package main import ( "flag" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/pkg/server" "github.com/openshift/machine-config-operator/pkg/version" "github.com/spf13/cobra" + "k8s.io/klog/v2" ) var ( @@ -34,12 +34,12 @@ func runBootstrapCmd(cmd *cobra.Command, args []string) { flag.Parse() // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) bs, err := server.NewBootstrapServer(bootstrapOpts.serverBaseDir, bootstrapOpts.serverKubeConfig) if err != nil { - glog.Exitf("Machine Config Server exited with error: %v", err) + klog.Exitf("Machine Config Server exited with error: %v", err) } apiHandler := server.NewServerAPIHandler(bs) diff --git a/cmd/machine-config-server/start.go b/cmd/machine-config-server/start.go index dbe6129308..02226dd9dd 100644 --- a/cmd/machine-config-server/start.go +++ b/cmd/machine-config-server/start.go @@ -3,11 +3,11 @@ package main import ( "flag" - "github.com/golang/glog" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/server" "github.com/openshift/machine-config-operator/pkg/version" "github.com/spf13/cobra" + "k8s.io/klog/v2" ) var ( @@ -35,10 +35,10 @@ func runStartCmd(cmd *cobra.Command, args []string) { flag.Parse() // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) if startOpts.apiserverURL == "" { - glog.Exitf("--apiserver-url cannot be empty") + klog.Exitf("--apiserver-url cannot be empty") } cs, err := server.NewClusterServer(startOpts.kubeconfig, startOpts.apiserverURL) diff --git a/cmd/machine-os-builder/start.go b/cmd/machine-os-builder/start.go index ef85cfcc64..5b15d06ec1 100644 --- a/cmd/machine-os-builder/start.go +++ b/cmd/machine-os-builder/start.go @@ -3,9 +3,9 @@ package main import ( "flag" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/pkg/version" "github.com/spf13/cobra" + "k8s.io/klog/v2" ) var ( @@ -30,9 +30,9 @@ func runStartCmd(cmd *cobra.Command, args []string) { flag.Set("logtostderr", "true") flag.Parse() - glog.V(2).Infof("Options parsed: %+v", startOpts) + klog.V(2).Infof("Options parsed: %+v", startOpts) // To help debugging, immediately log version - glog.Infof("Version: %+v (%s)", version.Raw, version.Hash) + klog.Infof("Version: %+v (%s)", version.Raw, version.Hash) } diff --git a/go.mod b/go.mod index d6a963ffb9..d6c7a60176 100644 --- a/go.mod +++ b/go.mod @@ -20,8 +20,7 @@ require ( github.com/coreos/rpmostree-client-go v0.0.0-20230303152616-d29525c6e333 github.com/davecgh/go-spew v1.1.1 github.com/fsnotify/fsnotify v1.6.0 - github.com/ghodss/yaml v1.0.0 - github.com/golang/glog v1.0.0 + github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/golangci/golangci-lint v1.49.0 github.com/google/go-cmp v0.5.9 github.com/google/renameio v0.1.0 diff --git a/go.sum b/go.sum index 47963bafff..1a035f596e 100644 --- a/go.sum +++ b/go.sum @@ -448,8 +448,6 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= -github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/hack/cluster-push.sh b/hack/cluster-push.sh index d1b296019b..437f07f925 100755 --- a/hack/cluster-push.sh +++ b/hack/cluster-push.sh @@ -34,13 +34,10 @@ if [[ "${podman:-}" =~ "docker" ]]; then else imgstorage="containers-storage:" fi -# skopeo copy --dest-tls-verify=false --dest-creds unused:${secret} "${imgstorage}${LOCAL_IMGNAME}" "docker://${registry}/${REMOTE_IMGNAME}" +skopeo copy --dest-tls-verify=false --dest-creds unused:${secret} "${imgstorage}${LOCAL_IMGNAME}" "docker://${registry}/${REMOTE_IMGNAME}" -podman tag "$LOCAL_IMGNAME" "$registry/$REMOTE_IMGNAME" -podman push --tls-verify=false --creds "unused:$secret" "$LOCAL_IMGNAME" "$registry/$REMOTE_IMGNAME" - -digest="$(skopeo inspect --creds "unused:${secret}" --tls-verify=false "docker://${registry}/${REMOTE_IMGNAME}" | jq -r '.Digest')" -imageid="${REMOTE_IMGNAME}@${digest}" +digest=$(skopeo inspect --creds unused:${secret} --tls-verify=false docker://${registry}/${REMOTE_IMGNAME} | jq -r .Digest) +imageid=${REMOTE_IMGNAME}@${digest} oc project openshift-machine-config-operator diff --git a/internal/clients/builder.go b/internal/clients/builder.go index 081556bc40..ea3d0aff26 100644 --- a/internal/clients/builder.go +++ b/internal/clients/builder.go @@ -3,7 +3,6 @@ package clients import ( "os" - "github.com/golang/glog" configclientset "github.com/openshift/client-go/config/clientset/versioned" operatorclientset "github.com/openshift/client-go/operator/clientset/versioned" mcfgclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" @@ -11,6 +10,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + "k8s.io/klog/v2" ) // Builder can create a variety of kubernetes client interface @@ -71,10 +71,10 @@ func NewBuilder(kubeconfig string) (*Builder, error) { } if kubeconfig != "" { - glog.V(4).Infof("Loading kube client config from path %q", kubeconfig) + klog.V(4).Infof("Loading kube client config from path %q", kubeconfig) config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) } else { - glog.V(4).Infof("Using in-cluster kube client config") + klog.V(4).Infof("Using in-cluster kube client config") config, err = rest.InClusterConfig() } if err != nil { diff --git a/pkg/controller/bootstrap/bootstrap.go b/pkg/controller/bootstrap/bootstrap.go index 1132825a46..116d98c30d 100644 --- a/pkg/controller/bootstrap/bootstrap.go +++ b/pkg/controller/bootstrap/bootstrap.go @@ -10,13 +10,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/golang/glog" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/runtime/serializer/json" yamlutil "k8s.io/apimachinery/pkg/util/yaml" kscheme "k8s.io/client-go/kubernetes/scheme" + "k8s.io/klog/v2" apicfgv1 "github.com/openshift/api/config/v1" apioperatorsv1alpha1 "github.com/openshift/api/operator/v1alpha1" @@ -105,7 +105,7 @@ func (b *Bootstrap) Run(destDir string) error { if err != nil { if runtime.IsNotRegisteredError(err) { // don't care - glog.V(4).Infof("skipping path %q [%d] manifest because it is not part of expected api group: %v", file.Name(), idx+1, err) + klog.V(4).Infof("skipping path %q [%d] manifest because it is not part of expected api group: %v", file.Name(), idx+1, err) continue } return fmt.Errorf("error parsing %q [%d] manifest: %w", file.Name(), idx+1, err) @@ -139,7 +139,7 @@ func (b *Bootstrap) Run(destDir string) error { nodeConfig = obj } default: - glog.Infof("skipping %q [%d] manifest because of unhandled %T", file.Name(), idx+1, obji) + klog.Infof("skipping %q [%d] manifest because of unhandled %T", file.Name(), idx+1, obji) } } } diff --git a/pkg/controller/common/constants.go b/pkg/controller/common/constants.go index 12177c3618..fd736ad683 100644 --- a/pkg/controller/common/constants.go +++ b/pkg/controller/common/constants.go @@ -39,6 +39,10 @@ const ( // MachineConfigPoolMaster is the MachineConfigPool name given to the master MachineConfigPoolMaster = "master" + // MachineConfigPoolWorker is the MachineConfigPool name given to the worker MachineConfigPoolWorker = "worker" + + // LayeringEnabledPoolLabel is the label that enables the "layered" workflow path for a pool. + LayeringEnabledPoolLabel = "machineconfiguration.openshift.io/layering-enabled" ) diff --git a/pkg/controller/common/controller_context.go b/pkg/controller/common/controller_context.go index d08d78a0ee..c2ff78a71c 100644 --- a/pkg/controller/common/controller_context.go +++ b/pkg/controller/common/controller_context.go @@ -4,7 +4,6 @@ import ( "math/rand" "time" - "github.com/golang/glog" configinformers "github.com/openshift/client-go/config/informers/externalversions" operatorinformers "github.com/openshift/client-go/operator/informers/externalversions" "github.com/openshift/machine-config-operator/internal/clients" @@ -87,7 +86,7 @@ func CreateControllerContext(cb *clients.Builder, stop <-chan struct{}, targetNa assignFilterLabels := func(opts *metav1.ListOptions) { labelsMap, err := labels.ConvertSelectorToLabelsMap(opts.LabelSelector) if err != nil { - glog.Warningf("unable to convert selector %q to map: %v", opts.LabelSelector, err) + klog.Warningf("unable to convert selector %q to map: %v", opts.LabelSelector, err) return } opts.LabelSelector = labels.Merge(labelsMap, map[string]string{daemonconsts.OpenShiftOperatorManagedLabel: ""}).String() diff --git a/pkg/controller/common/helpers.go b/pkg/controller/common/helpers.go index 81fd8d1838..aa38540c19 100644 --- a/pkg/controller/common/helpers.go +++ b/pkg/controller/common/helpers.go @@ -42,11 +42,11 @@ import ( ign3_4types "github.com/coreos/ignition/v2/config/v3_4/types" validate3 "github.com/coreos/ignition/v2/config/validate" "github.com/ghodss/yaml" - "github.com/golang/glog" "github.com/vincent-petithory/dataurl" kerr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" mcfgclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" @@ -255,7 +255,7 @@ func WriteTerminationError(err error) { // G306: Expect WriteFile permissions to be 0600 or less // #nosec os.WriteFile("/dev/termination-log", []byte(msg), 0o644) - glog.Fatal(msg) + klog.Fatal(msg) } // ConvertRawExtIgnitionToV3 ensures that the Ignition config in @@ -407,7 +407,7 @@ func convertIgnition2to3(ign2config ign2types.Config) (ign3types.Config, error) // Workaround to get a v3.2 config as output converted3 := translate3.Translate(translate3_1.Translate(ign3_0config)) - glog.V(4).Infof("Successfully translated Ignition spec v2 config to Ignition spec v3 config: %v", converted3) + klog.V(4).Infof("Successfully translated Ignition spec v2 config to Ignition spec v3 config: %v", converted3) return converted3, nil } @@ -417,7 +417,7 @@ func convertIgnition3to2(ign3config ign3types.Config) (ign2types.Config, error) if err != nil { return ign2types.Config{}, fmt.Errorf("unable to convert Ignition spec v3 config to v2: %w", err) } - glog.V(4).Infof("Successfully translated Ignition spec v3 config to Ignition spec v2 config: %v", converted2) + klog.V(4).Infof("Successfully translated Ignition spec v3 config to Ignition spec v2 config: %v", converted2) return converted2, nil } @@ -428,7 +428,7 @@ func convertIgnition32to31(ign3config ign3types.Config) (ign3_1types.Config, err if err != nil { return ign3_1types.Config{}, fmt.Errorf("unable to convert Ignition spec v3_2 config to v3_1: %w", err) } - glog.V(4).Infof("Successfully translated Ignition spec v3_2 config to Ignition spec v3_1 config: %v", converted31) + klog.V(4).Infof("Successfully translated Ignition spec v3_2 config to Ignition spec v3_1 config: %v", converted31) return converted31, nil } @@ -669,7 +669,7 @@ func ParseAndConvertGzippedConfig(rawIgn []byte) (ign3types.Config, error) { out, err := decodeAndDecompressPayload(bytes.NewReader(rawIgn)) if err == nil { // Our payload was decoded and decompressed, so parse it as Ignition. - glog.V(2).Info("ignition config was base64-decoded and gunzipped successfully") + klog.V(2).Info("ignition config was base64-decoded and gunzipped successfully") return ParseAndConvertConfig(out) } @@ -677,18 +677,18 @@ func ParseAndConvertGzippedConfig(rawIgn []byte) (ign3types.Config, error) { // e.g.: $ gzip -9 ign_config.json var base64Err base64.CorruptInputError if errors.As(err, &base64Err) { - glog.V(2).Info("ignition config was not base64 encoded, trying to gunzip ignition config") + klog.V(2).Info("ignition config was not base64 encoded, trying to gunzip ignition config") out, err = decompressPayload(bytes.NewReader(rawIgn)) if err == nil { // We were able to decompress our payload, so let's try parsing it - glog.V(2).Info("ignition config was gunzipped successfully") + klog.V(2).Info("ignition config was gunzipped successfully") return ParseAndConvertConfig(out) } } // Our Ignition config is not gzipped, so let's try to serialize the raw Ignition directly. if errors.Is(err, errConfigNotGzipped) { - glog.V(2).Info("ignition config was not gzipped") + klog.V(2).Info("ignition config was not gzipped") return ParseAndConvertConfig(rawIgn) } @@ -796,7 +796,7 @@ func removeIgnDuplicateFilesUnitsUsers(ignConfig ign2types.Config) (ign2types.Co continue } } - glog.V(2).Infof("Found duplicate unit %v, appending dropin section", unitName) + klog.V(2).Infof("Found duplicate unit %v, appending dropin section", unitName) } continue } @@ -949,7 +949,7 @@ func dedupePasswdUserSSHKeys(passwdUser ign2types.PasswdUser) ign2types.PasswdUs for _, sshKey := range passwdUser.SSHAuthorizedKeys { if _, isKnown := knownSSHKeys[sshKey]; isKnown { // We've seen this key before warn and move on. - glog.Warningf("duplicate SSH public key found: %s", sshKey) + klog.Warningf("duplicate SSH public key found: %s", sshKey) continue } @@ -983,7 +983,7 @@ func CalculateConfigFileDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []st _, ok := newFileSet[path] if !ok { // debug: remove - glog.Infof("File diff: %v was deleted", path) + klog.Infof("File diff: %v was deleted", path) diffFileSet = append(diffFileSet, path) } } @@ -993,11 +993,11 @@ func CalculateConfigFileDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []st oldFile, ok := oldFileSet[path] if !ok { // debug: remove - glog.Infof("File diff: %v was added", path) + klog.Infof("File diff: %v was added", path) diffFileSet = append(diffFileSet, path) } else if !reflect.DeepEqual(oldFile, newFile) { // debug: remove - glog.Infof("File diff: detected change to %v", newFile.Path) + klog.Infof("File diff: detected change to %v", newFile.Path) diffFileSet = append(diffFileSet, path) } } diff --git a/pkg/controller/common/metrics.go b/pkg/controller/common/metrics.go index 5c9f5d688b..29628112e9 100644 --- a/pkg/controller/common/metrics.go +++ b/pkg/controller/common/metrics.go @@ -5,9 +5,9 @@ import ( "fmt" "net/http" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "k8s.io/klog/v2" ) const ( @@ -71,29 +71,29 @@ func StartMetricsListener(addr string, stopCh <-chan struct{}, registerFunc func addr = DefaultBindAddress } - glog.Info("Registering Prometheus metrics") + klog.Info("Registering Prometheus metrics") if err := registerFunc(); err != nil { - glog.Errorf("unable to register metrics: %v", err) + klog.Errorf("unable to register metrics: %v", err) // No sense in continuing starting the listener if this fails return } - glog.Infof("Starting metrics listener on %s", addr) + klog.Infof("Starting metrics listener on %s", addr) mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) s := http.Server{Addr: addr, Handler: mux} go func() { if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed { - glog.Errorf("metrics listener exited with error: %v", err) + klog.Errorf("metrics listener exited with error: %v", err) } }() <-stopCh if err := s.Shutdown(context.Background()); err != nil { if err != http.ErrServerClosed { - glog.Errorf("error stopping metrics listener: %v", err) + klog.Errorf("error stopping metrics listener: %v", err) } } else { - glog.Infof("Metrics listener successfully stopped") + klog.Infof("Metrics listener successfully stopped") } } diff --git a/pkg/controller/container-runtime-config/container_runtime_config_bootstrap.go b/pkg/controller/container-runtime-config/container_runtime_config_bootstrap.go index 7d7c437c28..f8bf77200b 100644 --- a/pkg/controller/container-runtime-config/container_runtime_config_bootstrap.go +++ b/pkg/controller/container-runtime-config/container_runtime_config_bootstrap.go @@ -3,12 +3,13 @@ package containerruntimeconfig import ( "fmt" - "github.com/golang/glog" + "github.com/openshift/library-go/pkg/operator/configobserver/featuregates" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/version" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/klog/v2" ) // RunContainerRuntimeBootstrap generates ignition configs at bootstrap @@ -42,7 +43,7 @@ func RunContainerRuntimeBootstrap(templateDir string, crconfigs []*mcfgv1.Contai if !ctrcfg.OverlaySize.IsZero() { storageTOML, err := mergeConfigChanges(originalStorageIgn, cfg, updateStorageConfig) if err != nil { - glog.V(2).Infoln(cfg, err, "error merging user changes to storage.conf: %v", err) + klog.V(2).Infoln(cfg, err, "error merging user changes to storage.conf: %v", err) } else { configFileList = append(configFileList, generatedConfigFile{filePath: storageConfigPath, data: storageTOML}) } diff --git a/pkg/controller/container-runtime-config/container_runtime_config_controller.go b/pkg/controller/container-runtime-config/container_runtime_config_controller.go index 818eac6826..bd4689ed33 100644 --- a/pkg/controller/container-runtime-config/container_runtime_config_controller.go +++ b/pkg/controller/container-runtime-config/container_runtime_config_controller.go @@ -10,7 +10,6 @@ import ( "github.com/clarketm/json" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" apicfgv1 "github.com/openshift/api/config/v1" apioperatorsv1alpha1 "github.com/openshift/api/operator/v1alpha1" configclientset "github.com/openshift/client-go/config/clientset/versioned" @@ -35,6 +34,7 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/client-go/util/retry" "k8s.io/client-go/util/workqueue" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -124,7 +124,7 @@ func New( configClient configclientset.Interface, ) *Controller { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&coreclientsetv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) ctrl := &Controller{ @@ -208,8 +208,8 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { return } - glog.Info("Starting MachineConfigController-ContainerRuntimeConfigController") - defer glog.Info("Shutting down MachineConfigController-ContainerRuntimeConfigController") + klog.Info("Starting MachineConfigController-ContainerRuntimeConfigController") + defer klog.Info("Shutting down MachineConfigController-ContainerRuntimeConfigController") for i := 0; i < workers; i++ { go wait.Until(ctrl.worker, time.Second, stopCh) @@ -284,14 +284,14 @@ func (ctrl *Controller) updateContainerRuntimeConfig(oldObj, newObj interface{}) newCtrCfg := newObj.(*mcfgv1.ContainerRuntimeConfig) if ctrConfigTriggerObjectChange(oldCtrCfg, newCtrCfg) { - glog.V(4).Infof("Update ContainerRuntimeConfig %s", oldCtrCfg.Name) + klog.V(4).Infof("Update ContainerRuntimeConfig %s", oldCtrCfg.Name) ctrl.enqueueContainerRuntimeConfig(newCtrCfg) } } func (ctrl *Controller) addContainerRuntimeConfig(obj interface{}) { cfg := obj.(*mcfgv1.ContainerRuntimeConfig) - glog.V(4).Infof("Adding ContainerRuntimeConfig %s", cfg.Name) + klog.V(4).Infof("Adding ContainerRuntimeConfig %s", cfg.Name) ctrl.enqueueContainerRuntimeConfig(cfg) } @@ -312,7 +312,7 @@ func (ctrl *Controller) deleteContainerRuntimeConfig(obj interface{}) { if err := ctrl.cascadeDelete(cfg); err != nil { utilruntime.HandleError(fmt.Errorf("couldn't delete object %#v: %w", cfg, err)) } else { - glog.V(4).Infof("Deleted ContainerRuntimeConfig %s and restored default config", cfg.Name) + klog.V(4).Infof("Deleted ContainerRuntimeConfig %s and restored default config", cfg.Name) } } @@ -394,13 +394,13 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { } if ctrl.queue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing containerruntimeconfig %v: %v", key, err) + klog.V(2).Infof("Error syncing containerruntimeconfig %v: %v", key, err) ctrl.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping containerruntimeconfig %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping containerruntimeconfig %q out of the queue: %v", key, err) ctrl.queue.Forget(key) ctrl.queue.AddAfter(key, 1*time.Minute) } @@ -412,13 +412,13 @@ func (ctrl *Controller) handleImgErr(err error, key interface{}) { } if ctrl.imgQueue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing image config %v: %v", key, err) + klog.V(2).Infof("Error syncing image config %v: %v", key, err) ctrl.imgQueue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping image config %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping image config %q out of the queue: %v", key, err) ctrl.imgQueue.Forget(key) ctrl.imgQueue.AddAfter(key, 1*time.Minute) } @@ -493,7 +493,7 @@ func (ctrl *Controller) syncStatusOnly(cfg *mcfgv1.ContainerRuntimeConfig, err e }) // If an error occurred in updating the status just log it if statusUpdateErr != nil { - glog.Warningf("error updating container runtime config status: %v", statusUpdateErr) + klog.Warningf("error updating container runtime config status: %v", statusUpdateErr) } // Want to return the actual error received from the sync function return err @@ -513,7 +513,7 @@ func (ctrl *Controller) addAnnotation(cfg *mcfgv1.ContainerRuntimeConfig, annota return updateErr }) if annotationUpdateErr != nil { - glog.Warningf("error updating the container runtime config with annotation key %q and value %q: %v", annotationKey, annotationVal, annotationUpdateErr) + klog.Warningf("error updating the container runtime config with annotation key %q and value %q: %v", annotationKey, annotationVal, annotationUpdateErr) } return annotationUpdateErr } @@ -523,9 +523,9 @@ func (ctrl *Controller) addAnnotation(cfg *mcfgv1.ContainerRuntimeConfig, annota // nolint: gocyclo func (ctrl *Controller) syncContainerRuntimeConfig(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing ContainerRuntimeconfig %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing ContainerRuntimeconfig %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing ContainerRuntimeconfig %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing ContainerRuntimeconfig %q (%v)", key, time.Since(startTime)) }() _, name, err := cache.SplitMetaNamespaceKey(key) @@ -536,7 +536,7 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error { // Fetch the ContainerRuntimeConfig cfg, err := ctrl.mccrLister.Get(name) if errors.IsNotFound(err) { - glog.V(2).Infof("ContainerRuntimeConfig %v has been deleted", key) + klog.V(2).Infof("ContainerRuntimeConfig %v has been deleted", key) return nil } if err != nil { @@ -573,7 +573,7 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error { if len(mcpPools) == 0 { err := fmt.Errorf("containerRuntimeConfig %v does not match any MachineConfigPools", key) - glog.V(2).Infof("%v", err) + klog.V(2).Infof("%v", err) return ctrl.syncStatusOnly(cfg, err) } @@ -608,7 +608,7 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error { if !ctrcfg.OverlaySize.IsZero() { storageTOML, err := mergeConfigChanges(originalStorageIgn, cfg, updateStorageConfig) if err != nil { - glog.V(2).Infoln(cfg, err, "error merging user changes to storage.conf: %v", err) + klog.V(2).Infoln(cfg, err, "error merging user changes to storage.conf: %v", err) ctrl.syncStatusOnly(cfg, err) } else { configFileList = append(configFileList, generatedConfigFile{filePath: storageConfigPath, data: storageTOML}) @@ -678,7 +678,7 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error { if err := ctrl.addFinalizerToContainerRuntimeConfig(cfg, mc); err != nil { return ctrl.syncStatusOnly(cfg, err, "could not add finalizers to ContainerRuntimeConfig: %v", err) } - glog.Infof("Applied ContainerRuntimeConfig %v on MachineConfigPool %v", key, pool.Name) + klog.Infof("Applied ContainerRuntimeConfig %v on MachineConfigPool %v", key, pool.Name) } if err := ctrl.cleanUpDuplicatedMC(); err != nil { return err @@ -732,15 +732,15 @@ func mergeConfigChanges(origFile *ign3types.File, cfg *mcfgv1.ContainerRuntimeCo // nolint: gocyclo func (ctrl *Controller) syncImageConfig(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing ImageConfig %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing ImageConfig %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing ImageConfig %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing ImageConfig %q (%v)", key, time.Since(startTime)) }() // Fetch the ImageConfig imgcfg, err := ctrl.imgLister.Get("cluster") if errors.IsNotFound(err) { - glog.V(2).Infof("ImageConfig 'cluster' does not exist or has been deleted") + klog.V(2).Infof("ImageConfig 'cluster' does not exist or has been deleted") return nil } if err != nil { @@ -753,7 +753,7 @@ func (ctrl *Controller) syncImageConfig(key string) error { // so that we can avoid adding that registry to blocked registries in /etc/containers/registries.conf clusterVersionCfg, err := ctrl.clusterVersionLister.Get("version") if errors.IsNotFound(err) { - glog.Infof("ClusterVersionConfig 'version' does not exist or has been deleted") + klog.Infof("ClusterVersionConfig 'version' does not exist or has been deleted") return nil } if err != nil { @@ -799,7 +799,7 @@ func (ctrl *Controller) syncImageConfig(key string) error { // Go through the registries in the image spec to get and validate the blocked registries registriesBlocked, policyBlocked, allowedRegs, err = getValidBlockedAndAllowedRegistries(releaseImage, &imgcfg.Spec, icspRules, idmsRules) if err != nil && err != errParsingReference { - glog.V(2).Infof("%v, skipping....", err) + klog.V(2).Infof("%v, skipping....", err) } else if err == errParsingReference { return err } @@ -885,7 +885,7 @@ func (ctrl *Controller) syncImageConfig(key string) error { return fmt.Errorf("could not Create/Update MachineConfig: %w", err) } if applied { - glog.Infof("Applied ImageConfig cluster on MachineConfigPool %v", pool.Name) + klog.Infof("Applied ImageConfig cluster on MachineConfigPool %v", pool.Name) } } @@ -965,7 +965,7 @@ func RunImageBootstrap(templateDir string, controllerConfig *mcfgv1.ControllerCo searchRegs = imgCfg.Spec.RegistrySources.ContainerRuntimeSearchRegistries registriesBlocked, policyBlocked, allowedRegs, err = getValidBlockedAndAllowedRegistries(controllerConfig.Spec.ReleaseImage, &imgCfg.Spec, icspRules, idmsRules) if err != nil && err != errParsingReference { - glog.V(2).Infof("%v, skipping....", err) + klog.V(2).Infof("%v, skipping....", err) } else if err == errParsingReference { return nil, err } diff --git a/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go b/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go index ce3f3c5db7..8db3586ac1 100644 --- a/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go +++ b/pkg/controller/container-runtime-config/container_runtime_config_controller_test.go @@ -9,9 +9,9 @@ import ( "k8s.io/apimachinery/pkg/api/resource" - "github.com/golang/glog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "k8s.io/klog/v2" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -91,7 +91,7 @@ func (f *fixture) validateActions() { } actions := filterInformerActions(f.client.Actions()) for i, action := range actions { - glog.Infof("Action: %v", action) + klog.Infof("Action: %v", action) if len(f.actions) < i+1 { f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.actions), actions[i:]) @@ -568,7 +568,7 @@ func TestContainerRuntimeConfigUpdate(t *testing.T) { c = f.newController() stopCh = make(chan struct{}) - glog.Info("Applying update") + klog.Info("Applying update") // Apply update err = c.syncHandler(getKey(ctrcfgUpdate, t)) @@ -702,7 +702,7 @@ func TestImageConfigUpdate(t *testing.T) { c = f.newController() stopCh = make(chan struct{}) - glog.Info("Applying update") + klog.Info("Applying update") // Apply update err = c.syncImgHandler("") @@ -807,7 +807,7 @@ func TestICSPUpdate(t *testing.T) { c = f.newController() stopCh = make(chan struct{}) - glog.Info("Applying update") + klog.Info("Applying update") // Apply update err = c.syncImgHandler("") @@ -910,7 +910,7 @@ func TestIDMSUpdate(t *testing.T) { c = f.newController() stopCh = make(chan struct{}) - glog.Info("Applying update") + klog.Info("Applying update") // Apply update err = c.syncImgHandler("") @@ -1013,7 +1013,7 @@ func TestITMSUpdate(t *testing.T) { c = f.newController() stopCh = make(chan struct{}) - glog.Info("Applying update") + klog.Info("Applying update") // Apply update err = c.syncImgHandler("") diff --git a/pkg/controller/container-runtime-config/helpers.go b/pkg/controller/container-runtime-config/helpers.go index b9d74ed0a9..58c632cab8 100644 --- a/pkg/controller/container-runtime-config/helpers.go +++ b/pkg/controller/container-runtime-config/helpers.go @@ -18,7 +18,6 @@ import ( "github.com/containers/image/v5/types" storageconfig "github.com/containers/storage/pkg/config" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" apicfgv1 "github.com/openshift/api/config/v1" apioperatorsv1alpha1 "github.com/openshift/api/operator/v1alpha1" "github.com/openshift/runtime-utils/pkg/registries" @@ -26,6 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -336,7 +336,7 @@ func createCRIODropinFiles(cfg *mcfgv1.ContainerRuntimeConfig) []generatedConfig tomlConf.Crio.Runtime.LogLevel = ctrcfg.LogLevel generatedConfigFileList, err = addTOMLgeneratedConfigFile(generatedConfigFileList, CRIODropInFilePathLogLevel, tomlConf) if err != nil { - glog.V(2).Infoln(cfg, err, "error updating user changes for log-level to crio.conf.d: %v", err) + klog.V(2).Infoln(cfg, err, "error updating user changes for log-level to crio.conf.d: %v", err) } } if ctrcfg.PidsLimit != nil { @@ -344,7 +344,7 @@ func createCRIODropinFiles(cfg *mcfgv1.ContainerRuntimeConfig) []generatedConfig tomlConf.Crio.Runtime.PidsLimit = *ctrcfg.PidsLimit generatedConfigFileList, err = addTOMLgeneratedConfigFile(generatedConfigFileList, crioDropInFilePathPidsLimit, tomlConf) if err != nil { - glog.V(2).Infoln(cfg, err, "error updating user changes for pids-limit to crio.conf.d: %v", err) + klog.V(2).Infoln(cfg, err, "error updating user changes for pids-limit to crio.conf.d: %v", err) } } if ctrcfg.LogSizeMax.Value() != 0 { @@ -352,7 +352,7 @@ func createCRIODropinFiles(cfg *mcfgv1.ContainerRuntimeConfig) []generatedConfig tomlConf.Crio.Runtime.LogSizeMax = ctrcfg.LogSizeMax.Value() generatedConfigFileList, err = addTOMLgeneratedConfigFile(generatedConfigFileList, crioDropInFilePathLogSizeMax, tomlConf) if err != nil { - glog.V(2).Infoln(cfg, err, "error updating user changes for log-size-max to crio.conf.d: %v", err) + klog.V(2).Infoln(cfg, err, "error updating user changes for log-size-max to crio.conf.d: %v", err) } } if ctrcfg.DefaultRuntime != mcfgv1.ContainerRuntimeDefaultRuntimeEmpty { @@ -360,7 +360,7 @@ func createCRIODropinFiles(cfg *mcfgv1.ContainerRuntimeConfig) []generatedConfig tomlConf.Crio.Runtime.DefaultRuntime = string(ctrcfg.DefaultRuntime) generatedConfigFileList, err = addTOMLgeneratedConfigFile(generatedConfigFileList, CRIODropInFilePathDefaultRuntime, tomlConf) if err != nil { - glog.V(2).Infoln(cfg, err, "error updating user changes for default-runtime to crio.conf.d: %v", err) + klog.V(2).Infoln(cfg, err, "error updating user changes for default-runtime to crio.conf.d: %v", err) } } return generatedConfigFileList @@ -377,7 +377,7 @@ func updateSearchRegistriesConfig(searchRegs []string) []generatedConfigFile { tomlConf.UnqualifiedSearchRegistries = searchRegs generatedConfigFileList, err = addTOMLgeneratedConfigFile(generatedConfigFileList, searchRegDropInFilePath, tomlConf) if err != nil { - glog.Warningln("error updating user changes for containerRuntimeSearchRegistries to registries.conf.d: ", err) + klog.Warningln("error updating user changes for containerRuntimeSearchRegistries to registries.conf.d: ", err) } return generatedConfigFileList } @@ -562,7 +562,7 @@ func getValidBlockedAndAllowedRegistries(releaseImage string, imgSpec *apicfgv1. continue } // Log a warning that we are adding the payload registries to the blocked registries list as there are mirror rules for it - glog.Warningf("%q matches the payload repository, but will add it to the list of blocked registries as there are mirror rules configured for it", reg) + klog.Warningf("%q matches the payload repository, but will add it to the list of blocked registries as there are mirror rules configured for it", reg) // Intentionally do NOT add reg to policyBlocked, to allow using payloadRepo (physically accessing the mirrors) // In the future, this will be user-controlled via https://github.com/openshift/api/blob/1a6fa2913810101176a1d776f899fc4781b3fa50/config/v1/types_image_digest_mirror_set.go#L74 registriesBlocked = append(registriesBlocked, reg) diff --git a/pkg/controller/drain/drain_controller.go b/pkg/controller/drain/drain_controller.go index fc21d65796..263c881a8d 100644 --- a/pkg/controller/drain/drain_controller.go +++ b/pkg/controller/drain/drain_controller.go @@ -3,11 +3,12 @@ package drain import ( "context" "encoding/json" + "fmt" + "strings" "time" - "github.com/golang/glog" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants" mcfgclientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" @@ -28,6 +29,7 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/client-go/util/retry" "k8s.io/client-go/util/workqueue" + "k8s.io/klog/v2" "k8s.io/kubectl/pkg/drain" ) @@ -107,7 +109,7 @@ func New( mcfgClient mcfgclientset.Interface, ) *Controller { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&coreclientsetv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) ctrl := &Controller{ @@ -155,8 +157,8 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { ongoingDrains := make(map[string]time.Time) ctrl.ongoingDrains = ongoingDrains - glog.Info("Starting MachineConfigController-DrainController") - defer glog.Info("Shutting down MachineConfigController-DrainController") + klog.Info("Starting MachineConfigController-DrainController") + defer klog.Info("Shutting down MachineConfigController-DrainController") for i := 0; i < workers; i++ { go wait.Until(ctrl.worker, ctrl.cfg.WaitUntil, stopCh) @@ -168,12 +170,12 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { // logNode emits a log message at informational level, prefixed with the node name in a consistent fashion. func (ctrl *Controller) logNode(node *corev1.Node, format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) - glog.Infof("node %s: %s", node.Name, msg) + klog.Infof("node %s: %s", node.Name, msg) } func (ctrl *Controller) handleNodeEvent(node interface{}) { n := node.(*corev1.Node) - glog.V(4).Infof("Updating Node %s", n.Name) + klog.V(4).Infof("Updating Node %s", n.Name) ctrl.enqueueNode(n) } @@ -240,22 +242,22 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { } if ctrl.queue.NumRequeues(key) < ctrl.cfg.MaxRetries { - glog.V(2).Infof("Error syncing node %v: %v", key, err) + klog.V(2).Infof("Error syncing node %v: %v", key, err) ctrl.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping node %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping node %q out of the queue: %v", key, err) ctrl.queue.Forget(key) ctrl.queue.AddAfter(key, 1*time.Minute) } func (ctrl *Controller) syncNode(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing node %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing node %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing node %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing node %q (%v)", key, time.Since(startTime)) }() _, name, err := cache.SplitMetaNamespaceKey(key) @@ -266,7 +268,7 @@ func (ctrl *Controller) syncNode(key string) error { // First check if a drain request is needed for this node node, err := ctrl.nodeLister.Get(name) if apierrors.IsNotFound(err) { - glog.V(2).Infof("node %v has been deleted", key) + klog.V(2).Infof("node %v has been deleted", key) return nil } if err != nil { @@ -275,7 +277,7 @@ func (ctrl *Controller) syncNode(key string) error { desiredState := node.Annotations[daemonconsts.DesiredDrainerAnnotationKey] if desiredState == node.Annotations[daemonconsts.LastAppliedDrainerAnnotationKey] { - glog.V(4).Infof("Node %v has the correct drain", key) + klog.V(4).Infof("Node %v has the correct drain", key) return nil } @@ -293,8 +295,8 @@ func (ctrl *Controller) syncNode(key string) error { } ctrl.logNode(node, "%s pod %s/%s", verbStr, pod.Namespace, pod.Name) }, - Out: writer{glog.Info}, - ErrOut: writer{glog.Error}, + Out: writer{klog.Info}, + ErrOut: writer{klog.Error}, Ctx: context.TODO(), } @@ -345,9 +347,9 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro } isOngoingDrain = true duration = time.Now().Sub(v) - glog.Infof("Previous node drain found. Drain has been going on for %v hours", duration.Hours()) + klog.Infof("Previous node drain found. Drain has been going on for %v hours", duration.Hours()) if duration > ctrl.cfg.DrainTimeoutDuration { - glog.Errorf("node %s: drain exceeded timeout: %v. Will continue to retry.", node.Name, ctrl.cfg.DrainTimeoutDuration) + klog.Errorf("node %s: drain exceeded timeout: %v. Will continue to retry.", node.Name, ctrl.cfg.DrainTimeoutDuration) ctrlcommon.MCCDrainErr.WithLabelValues(node.Name).Set(1) } break @@ -388,7 +390,7 @@ func (ctrl *Controller) drainNode(node *corev1.Node, drainer *drain.Helper) erro // Clear the MCCDrainErr, if any. if ctrlcommon.MCCDrainErr.DeleteLabelValues(node.Name) { - glog.Infof("Cleaning up MCCDrain error for node(%s) as drain was completed", node.Name) + klog.Infof("Cleaning up MCCDrain error for node(%s) as drain was completed", node.Name) } return nil @@ -446,7 +448,7 @@ func (ctrl *Controller) cordonOrUncordonNode(desired bool, node *corev1.Node, dr err := drain.RunCordonOrUncordon(drainer, node, desired) if err != nil { lastErr = err - glog.Infof("%s failed with: %v, retrying", verb, err) + klog.Infof("%s failed with: %v, retrying", verb, err) return false, nil } @@ -454,7 +456,7 @@ func (ctrl *Controller) cordonOrUncordonNode(desired bool, node *corev1.Node, dr var updatedNode *corev1.Node if updatedNode, err = ctrl.kubeClient.CoreV1().Nodes().Get(context.TODO(), node.Name, metav1.GetOptions{}); err != nil { lastErr = err - glog.Errorf("Failed to fetch node %v, retrying", err) + klog.Errorf("Failed to fetch node %v, retrying", err) return false, nil } diff --git a/pkg/controller/kubelet-config/kubelet_config_controller.go b/pkg/controller/kubelet-config/kubelet_config_controller.go index 30623550c4..cadbb3ffe8 100644 --- a/pkg/controller/kubelet-config/kubelet_config_controller.go +++ b/pkg/controller/kubelet-config/kubelet_config_controller.go @@ -11,7 +11,6 @@ import ( "github.com/clarketm/json" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" "github.com/imdario/mergo" corev1 "k8s.io/api/core/v1" macherrors "k8s.io/apimachinery/pkg/api/errors" @@ -28,6 +27,7 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/client-go/util/retry" "k8s.io/client-go/util/workqueue" + "k8s.io/klog/v2" kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1" configv1 "github.com/openshift/api/config/v1" @@ -119,7 +119,7 @@ func New( configclient configclientset.Interface, ) *Controller { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&coreclientsetv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) ctrl := &Controller{ @@ -185,8 +185,8 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { return } - glog.Info("Starting MachineConfigController-KubeletConfigController") - defer glog.Info("Shutting down MachineConfigController-KubeletConfigController") + klog.Info("Starting MachineConfigController-KubeletConfigController") + defer klog.Info("Shutting down MachineConfigController-KubeletConfigController") for i := 0; i < workers; i++ { go wait.Until(ctrl.worker, time.Second, stopCh) @@ -218,14 +218,14 @@ func (ctrl *Controller) updateKubeletConfig(old, cur interface{}) { newConfig := cur.(*mcfgv1.KubeletConfig) if kubeletConfigTriggerObjectChange(oldConfig, newConfig) { - glog.V(4).Infof("Update KubeletConfig %s", oldConfig.Name) + klog.V(4).Infof("Update KubeletConfig %s", oldConfig.Name) ctrl.enqueueKubeletConfig(newConfig) } } func (ctrl *Controller) addKubeletConfig(obj interface{}) { cfg := obj.(*mcfgv1.KubeletConfig) - glog.V(4).Infof("Adding KubeletConfig %s", cfg.Name) + klog.V(4).Infof("Adding KubeletConfig %s", cfg.Name) ctrl.enqueueKubeletConfig(cfg) } @@ -246,7 +246,7 @@ func (ctrl *Controller) deleteKubeletConfig(obj interface{}) { if err := ctrl.cascadeDelete(cfg); err != nil { utilruntime.HandleError(fmt.Errorf("couldn't delete object %#v: %w", cfg, err)) } else { - glog.V(4).Infof("Deleted KubeletConfig %s and restored default config", cfg.Name) + klog.V(4).Infof("Deleted KubeletConfig %s and restored default config", cfg.Name) } } @@ -324,13 +324,13 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { } if ctrl.queue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing kubeletconfig %v: %v", key, err) + klog.V(2).Infof("Error syncing kubeletconfig %v: %v", key, err) ctrl.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping kubeletconfig %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping kubeletconfig %q out of the queue: %v", key, err) ctrl.queue.Forget(key) ctrl.queue.AddAfter(key, 1*time.Minute) } @@ -342,13 +342,13 @@ func (ctrl *Controller) handleFeatureErr(err error, key interface{}) { } if ctrl.featureQueue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing kubeletconfig %v: %v", key, err) + klog.V(2).Infof("Error syncing kubeletconfig %v: %v", key, err) ctrl.featureQueue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping featureconfig %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping featureconfig %q out of the queue: %v", key, err) ctrl.featureQueue.Forget(key) ctrl.featureQueue.AddAfter(key, 1*time.Minute) } @@ -421,7 +421,7 @@ func (ctrl *Controller) syncStatusOnly(cfg *mcfgv1.KubeletConfig, err error, arg return lerr }) if statusUpdateError != nil { - glog.Warningf("error updating kubeletconfig status: %v", statusUpdateError) + klog.Warningf("error updating kubeletconfig status: %v", statusUpdateError) } return err } @@ -454,7 +454,7 @@ func (ctrl *Controller) addAnnotation(cfg *mcfgv1.KubeletConfig, annotationKey, return updateErr }) if annotationUpdateErr != nil { - glog.Warningf("error updating the kubelet config with annotation key %q and value %q: %v", annotationKey, annotationVal, annotationUpdateErr) + klog.Warningf("error updating the kubelet config with annotation key %q and value %q: %v", annotationKey, annotationVal, annotationUpdateErr) } return annotationUpdateErr } @@ -465,9 +465,9 @@ func (ctrl *Controller) addAnnotation(cfg *mcfgv1.KubeletConfig, annotationKey, //nolint:gocyclo func (ctrl *Controller) syncKubeletConfig(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing kubeletconfig %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing kubeletconfig %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing kubeletconfig %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing kubeletconfig %q (%v)", key, time.Since(startTime)) }() // Wait to apply a kubelet config if the controller config is not completed @@ -483,7 +483,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error { // Fetch the KubeletConfig cfg, err := ctrl.mckLister.Get(name) if macherrors.IsNotFound(err) { - glog.V(2).Infof("KubeletConfig %v has been deleted", key) + klog.V(2).Infof("KubeletConfig %v has been deleted", key) return nil } if err != nil { @@ -519,7 +519,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error { if len(mcpPools) == 0 { err := fmt.Errorf("KubeletConfig %v does not match any MachineConfigPools", key) - glog.V(2).Infof("%v", err) + klog.V(2).Infof("%v", err) return ctrl.syncStatusOnly(cfg, err) } @@ -663,7 +663,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error { if err := ctrl.addFinalizerToKubeletConfig(cfg, mc); err != nil { return ctrl.syncStatusOnly(cfg, err, "could not add finalizers to KubeletConfig: %v", err) } - glog.Infof("Applied KubeletConfig %v on MachineConfigPool %v", key, pool.Name) + klog.Infof("Applied KubeletConfig %v on MachineConfigPool %v", key, pool.Name) } if err := ctrl.cleanUpDuplicatedMC(managedKubeletConfigKeyPrefix); err != nil { return err diff --git a/pkg/controller/kubelet-config/kubelet_config_controller_test.go b/pkg/controller/kubelet-config/kubelet_config_controller_test.go index 77750b9170..28663181eb 100644 --- a/pkg/controller/kubelet-config/kubelet_config_controller_test.go +++ b/pkg/controller/kubelet-config/kubelet_config_controller_test.go @@ -7,7 +7,6 @@ import ( "testing" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" osev1 "github.com/openshift/api/config/v1" oseconfigfake "github.com/openshift/client-go/config/clientset/versioned/fake" oseinformersv1 "github.com/openshift/client-go/config/informers/externalversions" @@ -25,6 +24,7 @@ import ( core "k8s.io/client-go/testing" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" + "k8s.io/klog/v2" kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1" "k8s.io/utils/pointer" @@ -98,7 +98,7 @@ func (f *fixture) validateActions() { return } for i, action := range actions { - glog.Infof(" Action: %v", action) + klog.Infof(" Action: %v", action) if len(f.actions) < i+1 { f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.actions), actions[i:]) @@ -534,7 +534,7 @@ func TestKubeletConfigAutoSizingReserved(t *testing.T) { } } -func TestKubeletConfigLogFile(t *testing.T) { +func TestKubeletConfiglogFile(t *testing.T) { for _, platform := range []osev1.PlatformType{osev1.AWSPlatformType, osev1.NonePlatformType, "unrecognized"} { t.Run(string(platform), func(t *testing.T) { f := newFixture(t) @@ -641,7 +641,7 @@ func TestKubeletConfigUpdates(t *testing.T) { c = f.newController() stopCh = make(chan struct{}) - glog.Info("Applying update") + klog.Info("Applying update") // Apply update err = c.syncHandler(getKey(kcUpdate, t)) diff --git a/pkg/controller/kubelet-config/kubelet_config_features.go b/pkg/controller/kubelet-config/kubelet_config_features.go index 8c07e3cfb6..c68c41b3bb 100644 --- a/pkg/controller/kubelet-config/kubelet_config_features.go +++ b/pkg/controller/kubelet-config/kubelet_config_features.go @@ -7,7 +7,6 @@ import ( "time" "github.com/clarketm/json" - "github.com/golang/glog" osev1 "github.com/openshift/api/config/v1" "github.com/openshift/library-go/pkg/cloudprovider" "k8s.io/apimachinery/pkg/api/errors" @@ -16,6 +15,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/retry" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -48,9 +48,9 @@ func (ctrl *Controller) processNextFeatureWorkItem() bool { func (ctrl *Controller) syncFeatureHandler(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing feature handler %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing feature handler %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing feature handler %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing feature handler %q (%v)", key, time.Since(startTime)) }() // Fetch the Feature @@ -129,7 +129,7 @@ func (ctrl *Controller) syncFeatureHandler(key string) error { }); err != nil { return fmt.Errorf("could not Create/Update MachineConfig: %w", err) } - glog.Infof("Applied FeatureSet %v on MachineConfigPool %v", key, pool.Name) + klog.Infof("Applied FeatureSet %v on MachineConfigPool %v", key, pool.Name) } if err := ctrl.cleanUpDuplicatedMC(managedFeaturesKeyPrefix); err != nil { return err @@ -151,14 +151,14 @@ func (ctrl *Controller) updateFeature(old, cur interface{}) { oldFeature := old.(*osev1.FeatureGate) newFeature := cur.(*osev1.FeatureGate) if !reflect.DeepEqual(oldFeature.Spec, newFeature.Spec) { - glog.V(4).Infof("Update Feature %s", newFeature.Name) + klog.V(4).Infof("Update Feature %s", newFeature.Name) ctrl.enqueueFeature(newFeature) } } func (ctrl *Controller) addFeature(obj interface{}) { features := obj.(*osev1.FeatureGate) - glog.V(4).Infof("Adding Feature %s", features.Name) + klog.V(4).Infof("Adding Feature %s", features.Name) ctrl.enqueueFeature(features) } @@ -176,7 +176,7 @@ func (ctrl *Controller) deleteFeature(obj interface{}) { return } } - glog.V(4).Infof("Deleted Feature %s and restored default config", features.Name) + klog.V(4).Infof("Deleted Feature %s and restored default config", features.Name) } // generateFeatureMap returns a map of enabled/disabled feature gate selection with exclusion list diff --git a/pkg/controller/kubelet-config/kubelet_config_nodes.go b/pkg/controller/kubelet-config/kubelet_config_nodes.go index e9dce08063..9fb6a63f06 100644 --- a/pkg/controller/kubelet-config/kubelet_config_nodes.go +++ b/pkg/controller/kubelet-config/kubelet_config_nodes.go @@ -7,7 +7,6 @@ import ( "time" "github.com/clarketm/json" - "github.com/golang/glog" osev1 "github.com/openshift/api/config/v1" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -19,6 +18,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/retry" + "k8s.io/klog/v2" ) func (ctrl *Controller) nodeConfigWorker() { @@ -45,13 +45,13 @@ func (ctrl *Controller) handleNodeConfigErr(err error, key interface{}) { } if ctrl.nodeConfigQueue.NumRequeues(key) < maxRetries { - glog.V(4).Infof("Error syncing node configuration %v: %v", key, err) + klog.V(4).Infof("Error syncing node configuration %v: %v", key, err) ctrl.nodeConfigQueue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping node config %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping node config %q out of the queue: %v", key, err) ctrl.nodeConfigQueue.Forget(key) ctrl.nodeConfigQueue.AddAfter(key, 1*time.Minute) } @@ -61,9 +61,9 @@ func (ctrl *Controller) handleNodeConfigErr(err error, key interface{}) { // node specific features such as cgroup modes, workerlatencyprofiles, etc. func (ctrl *Controller) syncNodeConfigHandler(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing nodeConfig handler %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing nodeConfig handler %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing nodeConfig handler %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing nodeConfig handler %q (%v)", key, time.Since(startTime)) }() // Fetch the Feature Gates @@ -82,7 +82,7 @@ func (ctrl *Controller) syncNodeConfigHandler(key string) error { } // checking if the Node spec is empty and accordingly returning from here. if reflect.DeepEqual(nodeConfig.Spec, osev1.NodeSpec{}) { - glog.V(2).Info("empty Node resource found") + klog.V(2).Info("empty Node resource found") return nil } @@ -160,7 +160,7 @@ func (ctrl *Controller) syncNodeConfigHandler(key string) error { }); err != nil { return fmt.Errorf("Could not Create/Update MachineConfig, error: %w", err) } - glog.Infof("Applied Node configuration %v on MachineConfigPool %v", key, pool.Name) + klog.Infof("Applied Node configuration %v on MachineConfigPool %v", key, pool.Name) } // fetch the kubeletconfigs kcs, err := ctrl.mckLister.List(labels.Everything()) @@ -202,7 +202,7 @@ func (ctrl *Controller) updateNodeConfig(old, cur interface{}) { if newNode.Name != ctrlcommon.ClusterNodeInstanceName { message := fmt.Sprintf("The node.config.openshift.io \"%v\" is invalid: metadata.name Invalid value: \"%v\" : must be \"%v\"", newNode.Name, newNode.Name, ctrlcommon.ClusterNodeInstanceName) ctrl.eventRecorder.Eventf(oldNode, corev1.EventTypeNormal, "ActionProhibited", message) - glog.V(2).Infof(message) + klog.V(2).Infof(message) return } if !reflect.DeepEqual(oldNode.Spec, newNode.Spec) { @@ -222,10 +222,10 @@ func (ctrl *Controller) updateNodeConfig(old, cur interface{}) { if !isValidWorkerLatencyProfleTransition { message := fmt.Sprintf("Skipping the Update Node event, name: %s, transition not allowed from old WorkerLatencyProfile: \"%s\" to new WorkerLatencyProfile: \"%s\"", newNode.Name, oldNode.Spec.WorkerLatencyProfile, newNode.Spec.WorkerLatencyProfile) ctrl.eventRecorder.Eventf(newNode, corev1.EventTypeNormal, "ActionProhibited", message) - glog.Infof(message) + klog.Infof(message) return } - glog.V(4).Infof("Updating the node config resource, name: %s", newNode.Name) + klog.V(4).Infof("Updating the node config resource, name: %s", newNode.Name) ctrl.enqueueNodeConfig(newNode) } } @@ -238,11 +238,11 @@ func (ctrl *Controller) addNodeConfig(obj interface{}) { } if nodeConfig.Name != ctrlcommon.ClusterNodeInstanceName { message := fmt.Sprintf("The node.config.openshift.io \"%v\" is invalid: metadata.name Invalid value: \"%v\" : must be \"%v\"", nodeConfig.Name, nodeConfig.Name, ctrlcommon.ClusterNodeInstanceName) - glog.V(2).Infof(message) + klog.V(2).Infof(message) ctrl.eventRecorder.Eventf(nodeConfig, corev1.EventTypeNormal, "ActionProhibited", message) return } - glog.V(4).Infof("Adding the node config resource, name: %s", nodeConfig.Name) + klog.V(4).Infof("Adding the node config resource, name: %s", nodeConfig.Name) ctrl.enqueueNodeConfig(nodeConfig) } @@ -260,7 +260,7 @@ func (ctrl *Controller) deleteNodeConfig(obj interface{}) { return } } - glog.V(4).Infof("Deleted node config %s and restored default config", nodeConfig.Name) + klog.V(4).Infof("Deleted node config %s and restored default config", nodeConfig.Name) } func RunNodeConfigBootstrap(templateDir string, features *osev1.FeatureGate, cconfig *mcfgv1.ControllerConfig, nodeConfig *osev1.Node, mcpPools []*mcfgv1.MachineConfigPool) ([]*mcfgv1.MachineConfig, error) { @@ -269,7 +269,7 @@ func RunNodeConfigBootstrap(templateDir string, features *osev1.FeatureGate, cco } // checking if the Node spec is empty and accordingly returning from here. if reflect.DeepEqual(nodeConfig.Spec, osev1.NodeSpec{}) { - glog.V(2).Info("empty Node resource found") + klog.V(2).Info("empty Node resource found") return nil, nil } configs := []*mcfgv1.MachineConfig{} diff --git a/pkg/controller/node/node_controller.go b/pkg/controller/node/node_controller.go index f4b110c1ef..af2e340790 100644 --- a/pkg/controller/node/node_controller.go +++ b/pkg/controller/node/node_controller.go @@ -8,7 +8,6 @@ import ( "sort" "time" - "github.com/golang/glog" configv1 "github.com/openshift/api/config/v1" cligoinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1" cligolistersv1 "github.com/openshift/client-go/config/listers/config/v1" @@ -40,6 +39,7 @@ import ( "k8s.io/client-go/tools/record" clientretry "k8s.io/client-go/util/retry" "k8s.io/client-go/util/workqueue" + "k8s.io/klog/v2" ) const ( @@ -65,9 +65,6 @@ const ( // schedulerCRName that we're interested in watching. schedulerCRName = "cluster" - - // LayeringEnabledPoolLabel is the label that enables the "layered" workflow path for a pool. - LayeringEnabledPoolLabel = "machineconfiguration.openshift.io/layering-enabled" ) // Controller defines the node controller. @@ -106,7 +103,7 @@ func New( mcfgClient mcfgclientset.Interface, ) *Controller { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&coreclientsetv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) ctrl := &Controller{ @@ -158,8 +155,8 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { return } - glog.Info("Starting MachineConfigController-NodeController") - defer glog.Info("Shutting down MachineConfigController-NodeController") + klog.Info("Starting MachineConfigController-NodeController") + defer klog.Info("Shutting down MachineConfigController-NodeController") for i := 0; i < workers; i++ { go wait.Until(ctrl.worker, time.Second, stopCh) @@ -187,13 +184,13 @@ func (ctrl *Controller) checkMasterNodesOnAdd(obj interface{}) { func (ctrl *Controller) checkMasterNodesOnDelete(obj interface{}) { scheduler := obj.(*configv1.Scheduler) if scheduler.Name != schedulerCRName { - glog.V(4).Infof("We don't care about CRs other than cluster created for scheduler config") + klog.V(4).Infof("We don't care about CRs other than cluster created for scheduler config") return } currentMasters, err := ctrl.getCurrentMasters() if err != nil { err = fmt.Errorf("reconciling to make master nodes schedulable/unschedulable failed: %w", err) - glog.Error(err) + klog.Error(err) return } // On deletion make all masters unschedulable to restore default behaviour @@ -201,7 +198,7 @@ func (ctrl *Controller) checkMasterNodesOnDelete(obj interface{}) { if len(errs) > 0 { err = v1helpers.NewMultiLineAggregate(errs) err = fmt.Errorf("reconciling to make nodes schedulable/unschedulable failed: %w", err) - glog.Error(err) + klog.Error(err) return } return @@ -214,12 +211,12 @@ func (ctrl *Controller) checkMasterNodesOnUpdate(old, cur interface{}) { curScheduler := cur.(*configv1.Scheduler) if oldScheduler.Name != schedulerCRName || curScheduler.Name != schedulerCRName { - glog.V(4).Infof("We don't care about CRs other than cluster created for scheduler config") + klog.V(4).Infof("We don't care about CRs other than cluster created for scheduler config") return } if reflect.DeepEqual(oldScheduler.Spec, curScheduler.Spec) { - glog.V(4).Info("Scheduler config did not change") + klog.V(4).Info("Scheduler config did not change") return } @@ -296,7 +293,7 @@ func (ctrl *Controller) makeMasterNodeSchedulable(node *corev1.Node) error { func (ctrl *Controller) addMachineConfigPool(obj interface{}) { pool := obj.(*mcfgv1.MachineConfigPool) - glog.V(4).Infof("Adding MachineConfigPool %s", pool.Name) + klog.V(4).Infof("Adding MachineConfigPool %s", pool.Name) ctrl.enqueueMachineConfigPool(pool) } @@ -304,7 +301,7 @@ func (ctrl *Controller) updateMachineConfigPool(old, cur interface{}) { oldPool := old.(*mcfgv1.MachineConfigPool) curPool := cur.(*mcfgv1.MachineConfigPool) - glog.V(4).Infof("Updating MachineConfigPool %s", oldPool.Name) + klog.V(4).Infof("Updating MachineConfigPool %s", oldPool.Name) ctrl.enqueueMachineConfigPool(curPool) } @@ -322,7 +319,7 @@ func (ctrl *Controller) deleteMachineConfigPool(obj interface{}) { return } } - glog.V(4).Infof("Deleting MachineConfigPool %s", pool.Name) + klog.V(4).Infof("Deleting MachineConfigPool %s", pool.Name) // TODO(abhinavdahiya): handle deletes. } @@ -365,21 +362,21 @@ func (ctrl *Controller) reconcileMaster(node *corev1.Node) { mastersSchedulable, err := ctrl.getMastersSchedulable() if err != nil { err = fmt.Errorf("getting scheduler config failed: %w", err) - glog.Error(err) + klog.Error(err) return } if mastersSchedulable { err = ctrl.makeMasterNodeSchedulable(node) if err != nil { err = fmt.Errorf("failed making master Node schedulable: %w", err) - glog.Error(err) + klog.Error(err) return } } else if !mastersSchedulable { err = ctrl.makeMasterNodeUnSchedulable(node) if err != nil { err = fmt.Errorf("failed making master Node unschedulable: %w", err) - glog.Error(err) + klog.Error(err) return } } @@ -391,7 +388,7 @@ func (ctrl *Controller) reconcileMasters() { currentMasters, err := ctrl.getCurrentMasters() if err != nil { err = fmt.Errorf("reconciling to make master nodes schedulable/unschedulable failed: %w", err) - glog.Error(err) + klog.Error(err) return } for _, node := range currentMasters { @@ -412,13 +409,13 @@ func (ctrl *Controller) addNode(obj interface{}) { pools, err := ctrl.getPoolsForNode(node) if err != nil { - glog.Errorf("error finding pools for node %s: %v", node.Name, err) + klog.Errorf("error finding pools for node %s: %v", node.Name, err) return } if pools == nil { return } - glog.V(4).Infof("Node %s added", node.Name) + klog.V(4).Infof("Node %s added", node.Name) for _, pool := range pools { ctrl.enqueueMachineConfigPool(pool) } @@ -426,7 +423,7 @@ func (ctrl *Controller) addNode(obj interface{}) { func (ctrl *Controller) logPool(pool *mcfgv1.MachineConfigPool, format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) - glog.Infof("Pool %s: %s", pool.Name, msg) + klog.Infof("Pool %s: %s", pool.Name, msg) } func (ctrl *Controller) logPoolNode(pool *mcfgv1.MachineConfigPool, node *corev1.Node, format string, args ...interface{}) { @@ -436,7 +433,7 @@ func (ctrl *Controller) logPoolNode(pool *mcfgv1.MachineConfigPool, node *corev1 if zok { zonemsg = fmt.Sprintf("[zone=%s]", zone) } - glog.Infof("Pool %s%s: node %s: %s", pool.Name, zonemsg, node.Name, msg) + klog.Infof("Pool %s%s: node %s: %s", pool.Name, zonemsg, node.Name, msg) } func (ctrl *Controller) updateNode(old, cur interface{}) { @@ -453,13 +450,13 @@ func (ctrl *Controller) updateNode(old, cur interface{}) { pool, err := ctrl.getPrimaryPoolForNode(curNode) if err != nil { - glog.Errorf("error finding pool for node: %v", err) + klog.Errorf("error finding pool for node: %v", err) return } if pool == nil { return } - glog.V(4).Infof("Node %s updated", curNode.Name) + klog.V(4).Infof("Node %s updated", curNode.Name) // Let's be verbose when a node changes pool oldPool, err := ctrl.getPrimaryPoolForNode(oldNode) @@ -524,7 +521,7 @@ func (ctrl *Controller) updateNode(old, cur interface{}) { pools, err := ctrl.getPoolsForNode(curNode) if err != nil { - glog.Errorf("error finding pools for node: %v", err) + klog.Errorf("error finding pools for node: %v", err) return } if pools == nil { @@ -553,7 +550,7 @@ func (ctrl *Controller) deleteNode(obj interface{}) { pools, err := ctrl.getPoolsForNode(node) if err != nil { - glog.Errorf("error finding pools for node: %v", err) + klog.Errorf("error finding pools for node: %v", err) return } if pools == nil { @@ -562,10 +559,10 @@ func (ctrl *Controller) deleteNode(obj interface{}) { // Clear any associated MCCDrainErr, if any. if ctrlcommon.MCCDrainErr.DeleteLabelValues(node.Name) { - glog.Infof("Cleaning up MCCDrain error for node(%s) as it is being deleted", node.Name) + klog.Infof("Cleaning up MCCDrain error for node(%s) as it is being deleted", node.Name) } - glog.V(4).Infof("Node %s delete", node.Name) + klog.V(4).Infof("Node %s delete", node.Name) for _, pool := range pools { ctrl.enqueueMachineConfigPool(pool) } @@ -579,7 +576,7 @@ func (ctrl *Controller) getPoolsForNode(node *corev1.Node) ([]*mcfgv1.MachineCon if isWindows(node) { // This is not an error, is this a Windows Node and it won't be managed by MCO. We're explicitly logging // here at a high level to disambiguate this from other pools = nil scenario - glog.V(4).Infof("Node %v is a windows node so won't be managed by MCO", node.Name) + klog.V(4).Infof("Node %v is a windows node so won't be managed by MCO", node.Name) return nil, nil } pl, err := ctrl.mcpLister.List(labels.Everything()) @@ -628,7 +625,7 @@ func (ctrl *Controller) getPoolsForNode(node *corev1.Node) ([]*mcfgv1.MachineCon pls := []*mcfgv1.MachineConfigPool{} if master != nil { // if we have a custom pool and master, defer to master and return. - glog.Infof("Found master node that matches selector for custom pool %v, defaulting to master. This node will not have any custom role configuration as a result. Please review the node to make sure this is intended", custom[0].Name) + klog.Infof("Found master node that matches selector for custom pool %v, defaulting to master. This node will not have any custom role configuration as a result. Please review the node to make sure this is intended", custom[0].Name) ctrlcommon.MCCPoolAlert.WithLabelValues(custom[0].Name, fmt.Sprintf("Given both master and custom pools. Defaulting to master: custom %v", custom[0].Name)).Set(1) pls = append(pls, master) } else { @@ -727,13 +724,13 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { } if ctrl.queue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing machineconfigpool %v: %v", key, err) + klog.V(2).Infof("Error syncing machineconfigpool %v: %v", key, err) ctrl.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping machineconfigpool %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping machineconfigpool %q out of the queue: %v", key, err) ctrl.queue.Forget(key) ctrl.queue.AddAfter(key, 1*time.Minute) } @@ -742,9 +739,9 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { // This function is not meant to be invoked concurrently with the same key. func (ctrl *Controller) syncMachineConfigPool(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing machineconfigpool %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing machineconfigpool %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing machineconfigpool %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing machineconfigpool %q (%v)", key, time.Since(startTime)) }() _, name, err := cache.SplitMetaNamespaceKey(key) @@ -753,7 +750,7 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error { } machineconfigpool, err := ctrl.mcpLister.Get(name) if errors.IsNotFound(err) { - glog.V(2).Infof("MachineConfigPool %v has been deleted", key) + klog.V(2).Infof("MachineConfigPool %v has been deleted", key) return nil } if err != nil { @@ -764,7 +761,7 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error { // Previously we spammed the logs about empty pools. // Let's just pause for a bit here to let the renderer // initialize them. - glog.Infof("Pool %s is unconfigured, pausing %v for renderer to initialize", name, updateDelay) + klog.Infof("Pool %s is unconfigured, pausing %v for renderer to initialize", name, updateDelay) time.Sleep(updateDelay) return nil } @@ -785,7 +782,7 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error { if pool.Spec.Paused { if mcfgv1.IsMachineConfigPoolConditionTrue(pool.Status.Conditions, mcfgv1.MachineConfigPoolUpdating) { - glog.Infof("Pool %s is paused and will not update.", pool.Name) + klog.Infof("Pool %s is paused and will not update.", pool.Name) } return ctrl.syncStatusOnly(pool) } @@ -822,14 +819,14 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error { if hasInProgressTaint { if err := ctrl.removeUpdateInProgressTaint(ctx, node.Name); err != nil { err = fmt.Errorf("failed removing %s taint for node %s: %w", constants.NodeUpdateInProgressTaint.Key, node.Name, err) - glog.Error(err) + klog.Error(err) } } } else { if !hasInProgressTaint { if err := ctrl.setUpdateInProgressTaint(ctx, node.Name); err != nil { err = fmt.Errorf("failed applying %s taint for node %s: %w", constants.NodeUpdateInProgressTaint.Key, node.Name, err) - glog.Error(err) + klog.Error(err) } } } @@ -880,7 +877,7 @@ func (ctrl *Controller) getNodesForPool(pool *mcfgv1.MachineConfigPool) ([]*core for _, n := range initialNodes { p, err := ctrl.getPrimaryPoolForNode(n) if err != nil { - glog.Warningf("can't get pool for node %q: %v", n.Name, err) + klog.Warningf("can't get pool for node %q: %v", n.Name, err) continue } if p == nil { @@ -912,7 +909,7 @@ func (ctrl *Controller) setClusterConfigAnnotation(nodes []*corev1.Node) error { if err != nil { return err } - glog.Infof("Updated controlPlaneTopology annotation of node %s from %s to %s", node.Name, oldAnn, node.Annotations[daemonconsts.ClusterControlPlaneTopologyAnnotationKey]) + klog.Infof("Updated controlPlaneTopology annotation of node %s from %s to %s", node.Name, oldAnn, node.Annotations[daemonconsts.ClusterControlPlaneTopologyAnnotationKey]) } } return nil @@ -1007,14 +1004,14 @@ func (ctrl *Controller) filterControlPlaneCandidateNodes(pool *mcfgv1.MachineCon } etcdLeader, err := ctrl.getCurrentEtcdLeader(candidates) if err != nil { - glog.Warningf("Failed to find current etcd leader (continuing anyways): %v", err) + klog.Warningf("Failed to find current etcd leader (continuing anyways): %v", err) } var newCandidates []*corev1.Node for _, node := range candidates { if node == etcdLeader { // For now make this an event so we know it's working, even though it's more of a non-event ctrl.eventRecorder.Eventf(pool, corev1.EventTypeNormal, "DeferringEtcdLeaderUpdate", "Deferring update of etcd leader %s", node.Name) - glog.Infof("Deferring update of etcd leader: %s", node.Name) + klog.Infof("Deferring update of etcd leader: %s", node.Name) continue } newCandidates = append(newCandidates, node) @@ -1184,20 +1181,20 @@ func getErrorString(err error) string { // If a pool is labeled with 'LayeringEnabledPoolLabel', it returns false indicating that no action should be taken. // Otherwise, it returns true indicating that the node-controller can proceed with applying configurations to the pool. func shouldApplyConfigToPool(pool *mcfgv1.MachineConfigPool) bool { - glog.Info("Checking if node-controller should apply configurations to on-cluster-build pool") + klog.Info("Checking if node-controller should apply configurations to on-cluster-build pool") labels := pool.GetLabels() - _, exists := labels[LayeringEnabledPoolLabel] + _, exists := labels[ctrlcommon.LayeringEnabledPoolLabel] return !exists } func updateCandidateMachines(pool *mcfgv1.MachineConfigPool, candidates []*corev1.Node, capacity uint) error { if !shouldApplyConfigToPool(pool) { // Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything. - glog.Info("Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything.") + klog.Info("Pool is labeled with 'LayeringEnabledPoolLabel', don't do anything.") return nil } // Continue with the rest of the update logic for the pool - glog.Info("Continue with the rest of the update logic for the pool") + klog.Info("Continue with the rest of the update logic for the pool") return nil } diff --git a/pkg/controller/node/status.go b/pkg/controller/node/status.go index e8e0d5868f..344d3dbe15 100644 --- a/pkg/controller/node/status.go +++ b/pkg/controller/node/status.go @@ -5,13 +5,13 @@ import ( "fmt" "strings" - "github.com/golang/glog" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" "github.com/openshift/machine-config-operator/pkg/daemon/constants" daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/klog/v2" ) func (ctrl *Controller) syncStatusOnly(pool *mcfgv1.MachineConfigPool) error { @@ -87,7 +87,7 @@ func calculateStatus(pool *mcfgv1.MachineConfigPool, nodes []*corev1.Node) mcfgv supdating := mcfgv1.NewMachineConfigPoolCondition(mcfgv1.MachineConfigPoolUpdating, corev1.ConditionFalse, "", "") mcfgv1.SetMachineConfigPoolCondition(&status, *supdating) if status.Configuration.Name != pool.Spec.Configuration.Name || !equality.Semantic.DeepEqual(status.Configuration.Source, pool.Spec.Configuration.Source) { - glog.Infof("Pool %s: %s", pool.Name, updatedMsg) + klog.Infof("Pool %s: %s", pool.Name, updatedMsg) status.Configuration = pool.Spec.Configuration } } else { @@ -104,7 +104,7 @@ func calculateStatus(pool *mcfgv1.MachineConfigPool, nodes []*corev1.Node) mcfgv var nodeDegraded bool for _, m := range degradedMachines { - glog.Infof("Degraded Machine: %v and Degraded Reason: %v", m.Name, m.Annotations[constants.MachineConfigDaemonReasonAnnotationKey]) + klog.Infof("Degraded Machine: %v and Degraded Reason: %v", m.Name, m.Annotations[constants.MachineConfigDaemonReasonAnnotationKey]) } if degradedMachineCount > 0 { nodeDegraded = true @@ -134,7 +134,7 @@ func calculateStatus(pool *mcfgv1.MachineConfigPool, nodes []*corev1.Node) mcfgv // isNodeManaged checks whether the MCD has ever run on a node func isNodeManaged(node *corev1.Node) bool { if isWindows(node) { - glog.V(4).Infof("Node %v is a windows node so won't be managed by MCO", node.Name) + klog.V(4).Infof("Node %v is a windows node so won't be managed by MCO", node.Name) return false } if node.Annotations == nil { diff --git a/pkg/controller/render/render_controller.go b/pkg/controller/render/render_controller.go index 8c153604b4..4f893fe7d8 100644 --- a/pkg/controller/render/render_controller.go +++ b/pkg/controller/render/render_controller.go @@ -6,7 +6,6 @@ import ( "reflect" "time" - "github.com/golang/glog" mcoResourceApply "github.com/openshift/machine-config-operator/lib/resourceapply" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -28,6 +27,7 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" + "k8s.io/klog/v2" ) const ( @@ -79,7 +79,7 @@ func New( mcfgClient mcfgclientset.Interface, ) *Controller { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&corev1client.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) ctrl := &Controller{ @@ -121,8 +121,8 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { return } - glog.Info("Starting MachineConfigController-RenderController") - defer glog.Info("Shutting down MachineConfigController-RenderController") + klog.Info("Starting MachineConfigController-RenderController") + defer klog.Info("Shutting down MachineConfigController-RenderController") for i := 0; i < workers; i++ { go wait.Until(ctrl.worker, time.Second, stopCh) @@ -133,7 +133,7 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { func (ctrl *Controller) addMachineConfigPool(obj interface{}) { pool := obj.(*mcfgv1.MachineConfigPool) - glog.V(4).Infof("Adding MachineConfigPool %s", pool.Name) + klog.V(4).Infof("Adding MachineConfigPool %s", pool.Name) ctrl.enqueueMachineConfigPool(pool) } @@ -142,7 +142,7 @@ func (ctrl *Controller) updateMachineConfigPool(old, cur interface{}) { oldPool := old.(*mcfgv1.MachineConfigPool) curPool := cur.(*mcfgv1.MachineConfigPool) - glog.V(4).Infof("Updating MachineConfigPool %s", oldPool.Name) + klog.V(4).Infof("Updating MachineConfigPool %s", oldPool.Name) ctrl.enqueueMachineConfigPool(curPool) } @@ -160,7 +160,7 @@ func (ctrl *Controller) deleteMachineConfigPool(obj interface{}) { return } } - glog.V(4).Infof("Deleting MachineConfigPool %s", pool.Name) + klog.V(4).Infof("Deleting MachineConfigPool %s", pool.Name) // TODO(abhinavdahiya): handle deletes. } @@ -174,7 +174,7 @@ func (ctrl *Controller) addMachineConfig(obj interface{}) { controllerRef := metav1.GetControllerOf(mc) if controllerRef != nil { if pool := ctrl.resolveControllerRef(controllerRef); pool != nil { - glog.V(4).Infof("MachineConfig %s added", mc.Name) + klog.V(4).Infof("MachineConfig %s added", mc.Name) ctrl.enqueueMachineConfigPool(pool) return } @@ -182,11 +182,11 @@ func (ctrl *Controller) addMachineConfig(obj interface{}) { pools, err := ctrl.getPoolsForMachineConfig(mc) if err != nil { - glog.Errorf("error finding pools for machineconfig: %v", err) + klog.Errorf("error finding pools for machineconfig: %v", err) return } - glog.V(4).Infof("MachineConfig %s added", mc.Name) + klog.V(4).Infof("MachineConfig %s added", mc.Name) for _, p := range pools { ctrl.enqueueMachineConfigPool(p) } @@ -200,13 +200,13 @@ func (ctrl *Controller) updateMachineConfig(old, cur interface{}) { oldControllerRef := metav1.GetControllerOf(oldMC) controllerRefChanged := !reflect.DeepEqual(curControllerRef, oldControllerRef) if controllerRefChanged && oldControllerRef != nil { - glog.Errorf("machineconfig has changed controller, not allowed.") + klog.Errorf("machineconfig has changed controller, not allowed.") return } if curControllerRef != nil { if pool := ctrl.resolveControllerRef(curControllerRef); pool != nil { - glog.V(4).Infof("MachineConfig %s updated", curMC.Name) + klog.V(4).Infof("MachineConfig %s updated", curMC.Name) ctrl.enqueueMachineConfigPool(pool) return } @@ -214,11 +214,11 @@ func (ctrl *Controller) updateMachineConfig(old, cur interface{}) { pools, err := ctrl.getPoolsForMachineConfig(curMC) if err != nil { - glog.Errorf("error finding pools for machineconfig: %v", err) + klog.Errorf("error finding pools for machineconfig: %v", err) return } - glog.V(4).Infof("MachineConfig %s updated", curMC.Name) + klog.V(4).Infof("MachineConfig %s updated", curMC.Name) for _, p := range pools { ctrl.enqueueMachineConfigPool(p) } @@ -243,7 +243,7 @@ func (ctrl *Controller) deleteMachineConfig(obj interface{}) { controllerRef := metav1.GetControllerOf(mc) if controllerRef != nil { if pool := ctrl.resolveControllerRef(controllerRef); pool != nil { - glog.V(4).Infof("MachineConfig %s deleted", mc.Name) + klog.V(4).Infof("MachineConfig %s deleted", mc.Name) ctrl.enqueueMachineConfigPool(pool) return } @@ -251,11 +251,11 @@ func (ctrl *Controller) deleteMachineConfig(obj interface{}) { pools, err := ctrl.getPoolsForMachineConfig(mc) if err != nil { - glog.Errorf("error finding pools for machineconfig: %v", err) + klog.Errorf("error finding pools for machineconfig: %v", err) return } - glog.V(4).Infof("MachineConfig %s deleted", mc.Name) + klog.V(4).Infof("MachineConfig %s deleted", mc.Name) for _, p := range pools { ctrl.enqueueMachineConfigPool(p) } @@ -374,13 +374,13 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { } if ctrl.queue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing machineconfigpool %v: %v", key, err) + klog.V(2).Infof("Error syncing machineconfigpool %v: %v", key, err) ctrl.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping machineconfigpool %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping machineconfigpool %q out of the queue: %v", key, err) ctrl.queue.Forget(key) ctrl.queue.AddAfter(key, 1*time.Minute) } @@ -389,9 +389,9 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { // This function is not meant to be invoked concurrently with the same key. func (ctrl *Controller) syncMachineConfigPool(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing machineconfigpool %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing machineconfigpool %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing machineconfigpool %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing machineconfigpool %q (%v)", key, time.Since(startTime)) }() _, name, err := cache.SplitMetaNamespaceKey(key) @@ -400,7 +400,7 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error { } machineconfigpool, err := ctrl.mcpLister.Get(name) if errors.IsNotFound(err) { - glog.V(2).Infof("MachineConfigPool %v has been deleted", key) + klog.V(2).Infof("MachineConfigPool %v has been deleted", key) return nil } if err != nil { @@ -457,7 +457,7 @@ func (ctrl *Controller) syncFailingStatus(pool *mcfgv1.MachineConfigPool, err er sdegraded := mcfgv1.NewMachineConfigPoolCondition(mcfgv1.MachineConfigPoolRenderDegraded, corev1.ConditionTrue, "", fmt.Sprintf("Failed to render configuration for pool %s: %v", pool.Name, err)) mcfgv1.SetMachineConfigPoolCondition(&pool.Status, *sdegraded) if _, updateErr := ctrl.client.MachineconfigurationV1().MachineConfigPools().UpdateStatus(context.TODO(), pool, metav1.UpdateOptions{}); updateErr != nil { - glog.Errorf("Error updating MachineConfigPool %s: %v", pool.Name, updateErr) + klog.Errorf("Error updating MachineConfigPool %s: %v", pool.Name, updateErr) } return err } @@ -507,7 +507,7 @@ func (ctrl *Controller) syncGeneratedMachineConfig(pool *mcfgv1.MachineConfigPoo if err != nil { return err } - glog.V(2).Infof("Generated machineconfig %s from %d configs: %s", generated.Name, len(source), source) + klog.V(2).Infof("Generated machineconfig %s from %d configs: %s", generated.Name, len(source), source) ctrl.eventRecorder.Eventf(pool, corev1.EventTypeNormal, "RenderedConfigGenerated", "%s successfully generated (release version: %s, controller version: %s)", generated.Name, generated.Annotations[ctrlcommon.ReleaseImageVersionAnnotationKey], generated.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey]) } @@ -533,7 +533,7 @@ func (ctrl *Controller) syncGeneratedMachineConfig(pool *mcfgv1.MachineConfigPoo if err != nil { return err } - glog.V(2).Infof("Pool %s: now targeting: %s", pool.Name, pool.Spec.Configuration.Name) + klog.V(2).Infof("Pool %s: now targeting: %s", pool.Name, pool.Spec.Configuration.Name) if err := ctrl.garbageCollectRenderedConfigs(pool); err != nil { return err @@ -564,9 +564,9 @@ func generateRenderedMachineConfig(pool *mcfgv1.MachineConfigPool, configs []*mc } if cconfig.Spec.BaseOSContainerImage == "" { - glog.Warningf("No BaseOSContainerImage set") + klog.Warningf("No BaseOSContainerImage set") } else { - glog.Infof("BaseOSContainerImage=%s", cconfig.Spec.BaseOSContainerImage) + klog.Infof("BaseOSContainerImage=%s", cconfig.Spec.BaseOSContainerImage) } // Before merging all MCs for a specific pool, let's make sure MachineConfigs are valid diff --git a/pkg/controller/template/render.go b/pkg/controller/template/render.go index bf705ff459..9b88370849 100644 --- a/pkg/controller/template/render.go +++ b/pkg/controller/template/render.go @@ -11,7 +11,8 @@ import ( "strings" "text/template" - "github.com/golang/glog" + "k8s.io/klog/v2" + configv1 "github.com/openshift/api/config/v1" "github.com/openshift/library-go/pkg/cloudprovider" @@ -64,7 +65,7 @@ func generateTemplateMachineConfigs(config *RenderConfig, templateDir string) ([ for _, info := range infos { if !info.IsDir() { - glog.Infof("ignoring non-directory path %q", info.Name()) + klog.Infof("ignoring non-directory path %q", info.Name()) continue } role := info.Name() @@ -113,7 +114,7 @@ func GenerateMachineConfigsForRole(config *RenderConfig, role, templateDir strin var commonAdded bool for _, info := range infos { if !info.IsDir() { - glog.Infof("ignoring non-directory path %q", info.Name()) + klog.Infof("ignoring non-directory path %q", info.Name()) continue } name := info.Name() @@ -184,7 +185,7 @@ func platformStringFromControllerConfigSpec(ic *mcfgv1.ControllerConfigSpec) (st // platformNone is used for a non-empty, but currently unsupported platform. // This allows us to incrementally roll out new platforms across the project // by provisioning platforms before all support is added. - glog.Warningf("Warning: the controller config referenced an unsupported platform: %v", ic.Infra.Status.PlatformStatus.Type) + klog.Warningf("Warning: the controller config referenced an unsupported platform: %v", ic.Infra.Status.PlatformStatus.Type) return strings.ToLower(string(configv1.NonePlatformType)), nil } @@ -396,7 +397,7 @@ func cloudProvider(cfg RenderConfig) (interface{}, error) { if cfg.Infra.Status.PlatformStatus != nil { external, err := cloudprovider.IsCloudProviderExternal(cfg.Infra.Status.PlatformStatus, cfg.FeatureGate) if err != nil { - glog.Error(err) + klog.Error(err) } else if external { return "external", nil } @@ -441,7 +442,7 @@ func cloudConfigFlag(cfg RenderConfig) interface{} { external, err := cloudprovider.IsCloudProviderExternal(cfg.Infra.Status.PlatformStatus, cfg.FeatureGate) if err != nil { - glog.Error(err) + klog.Error(err) } else if external { return "" } @@ -693,7 +694,7 @@ func isOpenShiftManagedDefaultLB(cfg RenderConfig) bool { } return lbType == configv1.LoadBalancerTypeOpenShiftManagedDefault } - glog.Info("VSphere UPI doesn't populate VSphere PlatformStatus field. In that case we should return false") + klog.Info("VSphere UPI doesn't populate VSphere PlatformStatus field. In that case we should return false") return false case configv1.NutanixPlatformType: if cfg.Infra.Status.PlatformStatus.Nutanix != nil { diff --git a/pkg/controller/template/template_controller.go b/pkg/controller/template/template_controller.go index a474778ceb..9fc7cdb65d 100644 --- a/pkg/controller/template/template_controller.go +++ b/pkg/controller/template/template_controller.go @@ -9,8 +9,6 @@ import ( "sort" "time" - "github.com/golang/glog" - configv1 "github.com/openshift/api/config/v1" osev1 "github.com/openshift/api/config/v1" oseinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1" oselistersv1 "github.com/openshift/client-go/config/listers/config/v1" @@ -21,6 +19,7 @@ import ( "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme" mcfginformersv1 "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1" mcfglistersv1 "github.com/openshift/machine-config-operator/pkg/generated/listers/machineconfiguration.openshift.io/v1" + "k8s.io/klog/v2" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -81,7 +80,7 @@ func New( mcfgClient mcfgclientset.Interface, ) *Controller { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&corev1clientset.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) ctrl := &Controller{ @@ -134,7 +133,7 @@ func New( func (ctrl *Controller) filterSecret(secret *corev1.Secret) { if secret.Name == "pull-secret" { ctrl.enqueueController() - glog.Infof("Re-syncing ControllerConfig due to secret %s change", secret.Name) + klog.Infof("Re-syncing ControllerConfig due to secret %s change", secret.Name) } } @@ -144,19 +143,19 @@ func (ctrl *Controller) addSecret(obj interface{}) { ctrl.deleteSecret(secret) return } - glog.V(4).Infof("Add Secret %v", secret) + klog.V(4).Infof("Add Secret %v", secret) ctrl.filterSecret(secret) } func (ctrl *Controller) updateSecret(old, new interface{}) { secret := new.(*corev1.Secret) - glog.V(4).Infof("Update Secret %v", secret) + klog.V(4).Infof("Update Secret %v", secret) ctrl.filterSecret(secret) } func (ctrl *Controller) deleteSecret(obj interface{}) { secret, ok := obj.(*corev1.Secret) - glog.V(4).Infof("Delete Secret %v", secret) + klog.V(4).Infof("Delete Secret %v", secret) if !ok { tombstone, ok := obj.(cache.DeletedFinalStateUnknown) @@ -177,7 +176,7 @@ func (ctrl *Controller) deleteSecret(obj interface{}) { utilruntime.HandleError(fmt.Errorf("couldn't get ControllerConfig on secret callback %#w", err)) return } - glog.V(4).Infof("Re-syncing ControllerConfig %s due to secret deletion", cfg.Name) + klog.V(4).Infof("Re-syncing ControllerConfig %s due to secret deletion", cfg.Name) // TODO(runcom): should we resync w/o a secret which is going to just cause the controller to fail when trying to get the secret itself? // ctrl.enqueueControllerConfig(cfg) } @@ -189,7 +188,7 @@ func (ctrl *Controller) enqueueController() { utilruntime.HandleError(fmt.Errorf("couldn't get ControllerConfig on dependency callback %#w", err)) return } - glog.V(4).Infof("Re-syncing ControllerConfig %s due to dependency change", cfg.Name) + klog.V(4).Infof("Re-syncing ControllerConfig %s due to dependency change", cfg.Name) ctrl.enqueueControllerConfig(cfg) } @@ -197,14 +196,14 @@ func (ctrl *Controller) updateFeature(old, cur interface{}) { oldFeature := old.(*osev1.FeatureGate) newFeature := cur.(*osev1.FeatureGate) if !reflect.DeepEqual(oldFeature.Spec, newFeature.Spec) { - glog.V(4).Infof("Updating Feature: %s", newFeature.Name) + klog.V(4).Infof("Updating Feature: %s", newFeature.Name) ctrl.enqueueController() } } func (ctrl *Controller) addFeature(obj interface{}) { features := obj.(*osev1.FeatureGate) - glog.V(4).Infof("Adding Feature: %s", features.Name) + klog.V(4).Infof("Adding Feature: %s", features.Name) ctrl.enqueueController() } @@ -222,7 +221,7 @@ func (ctrl *Controller) deleteFeature(obj interface{}) { return } } - glog.V(4).Infof("Deleting Feature %s", features.Name) + klog.V(4).Infof("Deleting Feature %s", features.Name) ctrl.enqueueController() } @@ -235,8 +234,8 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { return } - glog.Info("Starting MachineConfigController-TemplateController") - defer glog.Info("Shutting down MachineConfigController-TemplateController") + klog.Info("Starting MachineConfigController-TemplateController") + defer klog.Info("Shutting down MachineConfigController-TemplateController") for i := 0; i < workers; i++ { go wait.Until(ctrl.worker, time.Second, stopCh) @@ -247,14 +246,14 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) { func (ctrl *Controller) addControllerConfig(obj interface{}) { cfg := obj.(*mcfgv1.ControllerConfig) - glog.V(4).Infof("Adding ControllerConfig %s", cfg.Name) + klog.V(4).Infof("Adding ControllerConfig %s", cfg.Name) ctrl.enqueueControllerConfig(cfg) } func (ctrl *Controller) updateControllerConfig(old, cur interface{}) { oldCfg := old.(*mcfgv1.ControllerConfig) curCfg := cur.(*mcfgv1.ControllerConfig) - glog.V(4).Infof("Updating ControllerConfig %s", oldCfg.Name) + klog.V(4).Infof("Updating ControllerConfig %s", oldCfg.Name) ctrl.enqueueControllerConfig(curCfg) } @@ -272,7 +271,7 @@ func (ctrl *Controller) deleteControllerConfig(obj interface{}) { return } } - glog.V(4).Infof("Deleting ControllerConfig %s", cfg.Name) + klog.V(4).Infof("Deleting ControllerConfig %s", cfg.Name) // TODO(abhinavdahiya): handle deletes. } @@ -288,7 +287,7 @@ func (ctrl *Controller) addMachineConfig(obj interface{}) { if cfg == nil { return } - glog.V(4).Infof("MachineConfig %s added", mc.Name) + klog.V(4).Infof("MachineConfig %s added", mc.Name) ctrl.enqueueControllerConfig(cfg) return } @@ -304,7 +303,7 @@ func (ctrl *Controller) updateMachineConfig(old, cur interface{}) { if cfg == nil { return } - glog.V(4).Infof("MachineConfig %s updated", curMC.Name) + klog.V(4).Infof("MachineConfig %s updated", curMC.Name) ctrl.enqueueControllerConfig(cfg) return } @@ -337,7 +336,7 @@ func (ctrl *Controller) deleteMachineConfig(obj interface{}) { if cfg == nil { return } - glog.V(4).Infof("MachineConfig %s deleted.", mc.Name) + klog.V(4).Infof("MachineConfig %s deleted.", mc.Name) ctrl.enqueueControllerConfig(cfg) } @@ -418,13 +417,13 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { } if ctrl.queue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing controllerconfig %v: %v", key, err) + klog.V(2).Infof("Error syncing controllerconfig %v: %v", key, err) ctrl.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping controllerconfig %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping controllerconfig %q out of the queue: %v", key, err) ctrl.queue.Forget(key) ctrl.queue.AddAfter(key, 1*time.Minute) } @@ -433,9 +432,9 @@ func (ctrl *Controller) handleErr(err error, key interface{}) { // This function is not meant to be invoked concurrently with the same key. func (ctrl *Controller) syncControllerConfig(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing controllerconfig %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing controllerconfig %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing controllerconfig %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing controllerconfig %q (%v)", key, time.Since(startTime)) }() _, name, err := cache.SplitMetaNamespaceKey(key) @@ -444,7 +443,7 @@ func (ctrl *Controller) syncControllerConfig(key string) error { } controllerconfig, err := ctrl.ccLister.Get(name) if errors.IsNotFound(err) { - glog.V(2).Infof("ControllerConfig %v has been deleted", key) + klog.V(2).Infof("ControllerConfig %v has been deleted", key) return nil } if err != nil { @@ -491,7 +490,7 @@ func (ctrl *Controller) syncControllerConfig(key string) error { return ctrl.syncFailingStatus(cfg, err) } if updated { - glog.V(4).Infof("Machineconfig %s was updated", mc.Name) + klog.V(4).Infof("Machineconfig %s was updated", mc.Name) } } diff --git a/pkg/daemon/certificate_writer.go b/pkg/daemon/certificate_writer.go index ac0113f478..3b07fd8a10 100644 --- a/pkg/daemon/certificate_writer.go +++ b/pkg/daemon/certificate_writer.go @@ -2,14 +2,15 @@ package daemon import ( "fmt" + "time" - "github.com/golang/glog" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/daemon/constants" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/cache" + "k8s.io/klog/v2" ) var ( @@ -18,7 +19,7 @@ var ( func (dn *Daemon) handleControllerConfigEvent(obj interface{}) { controllerConfig := obj.(*mcfgv1.ControllerConfig) - glog.V(4).Infof("Updating ControllerConfig %s", controllerConfig.Name) + klog.V(4).Infof("Updating ControllerConfig %s", controllerConfig.Name) dn.enqueueControllerConfig(controllerConfig) } @@ -66,18 +67,18 @@ func (dn *Daemon) handleControllerConfigErr(err error, key interface{}) { } if err := dn.updateErrorState(err); err != nil { - glog.Errorf("Could not update annotation: %v", err) + klog.Errorf("Could not update annotation: %v", err) } // This is at V(2) since the updateErrorState() call above ends up logging too - glog.V(2).Infof("Error syncing ControllerConfig %v (retries %d): %v", key, dn.ccQueue.NumRequeues(key), err) + klog.V(2).Infof("Error syncing ControllerConfig %v (retries %d): %v", key, dn.ccQueue.NumRequeues(key), err) dn.ccQueue.AddRateLimited(key) } func (dn *Daemon) syncControllerConfigHandler(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing ControllerConfig %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing ControllerConfig %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing ControllerConfig %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing ControllerConfig %q (%v)", key, time.Since(startTime)) }() if key != ctrlcommon.ControllerConfigName { @@ -114,7 +115,7 @@ func (dn *Daemon) syncControllerConfigHandler(key string) error { if _, err := dn.nodeWriter.SetAnnotations(annos); err != nil { return fmt.Errorf("failed to set ControllerConfigResourceVersion annotation on node: %w", err) } - glog.Infof("Certificate was synced from controllerconfig resourceVersion %s", controllerConfig.ObjectMeta.ResourceVersion) + klog.Infof("Certificate was synced from controllerconfig resourceVersion %s", controllerConfig.ObjectMeta.ResourceVersion) } return nil diff --git a/pkg/daemon/config_drift_monitor.go b/pkg/daemon/config_drift_monitor.go index ab9ff67a56..258ff0d04c 100644 --- a/pkg/daemon/config_drift_monitor.go +++ b/pkg/daemon/config_drift_monitor.go @@ -10,10 +10,10 @@ import ( ign2types "github.com/coreos/ignition/config/v2_2/types" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" "github.com/fsnotify/fsnotify" - "github.com/golang/glog" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/klog/v2" ) // Outermost error type for config drift errors @@ -181,8 +181,8 @@ func (c *configDriftWatcher) initialize() error { return fmt.Errorf("could not start watcher: %w", err) } - glog.V(4).Infof("Initializing Config Drift Monitor") - glog.V(4).Infof("Current MachineConfig: %s", c.MachineConfig.Name) + klog.V(4).Infof("Initializing Config Drift Monitor") + klog.V(4).Infof("Current MachineConfig: %s", c.MachineConfig.Name) // Even though we wire up fsnotify to use the parent directories of each // file, we keep track of the file paths individually so that we can ignore @@ -204,11 +204,11 @@ func (c *configDriftWatcher) initialize() error { // them and attach watchers to those dirs. dirPaths := getDirPathsFromFilePaths(c.filePaths) - glog.V(4).Infof("Will watch %d directories containing %d files:", len(dirPaths), len(c.filePaths)) + klog.V(4).Infof("Will watch %d directories containing %d files:", len(dirPaths), len(c.filePaths)) // Wire up fsnotify to watch our config dirs for _, path := range dirPaths { - glog.V(4).Infof("Watching dir: \"%s\"", path) + klog.V(4).Infof("Watching dir: \"%s\"", path) if err := c.watcher.Add(path); err != nil { return fmt.Errorf("could not add fsnotify watcher to dir \"%s\": %w", path, err) } @@ -243,7 +243,7 @@ func (c *configDriftWatcher) start() { } }() - glog.Info("Config Drift Monitor started") + klog.Info("Config Drift Monitor started") } // Stops the watcher. @@ -252,7 +252,7 @@ func (c *configDriftWatcher) start() { func (c *configDriftWatcher) stop() { c.stopCh <- struct{}{} c.wg.Wait() - glog.Info("Config Drift Monitor has shut down") + klog.Info("Config Drift Monitor has shut down") } // Handles the filesystem event for any of the files we're watching and diff --git a/pkg/daemon/coreos.go b/pkg/daemon/coreos.go index 3971ab1d95..4fa59ad5b9 100644 --- a/pkg/daemon/coreos.go +++ b/pkg/daemon/coreos.go @@ -9,7 +9,7 @@ import ( "io" "os" - "github.com/golang/glog" + "k8s.io/klog/v2" ) // alephPath contains information on the original bootimage; for more @@ -51,7 +51,7 @@ func logAlephInformation() error { if err := json.Unmarshal(contents, &alephData); err != nil { return err } - glog.Infof("CoreOS aleph version: mtime=%v build=%v imgid=%v\n", stat.ModTime().UTC(), alephData.Build, alephData.Imgid) + klog.Infof("CoreOS aleph version: mtime=%v build=%v imgid=%v\n", stat.ModTime().UTC(), alephData.Build, alephData.Imgid) return nil } @@ -68,15 +68,15 @@ func logInitionProvisioning() error { if err := json.Unmarshal(contents, &ignProvisioning); err != nil { return err } - glog.Infof("Ignition provisioning: time=%v\n", ignProvisioning.ProvisioningDate) + klog.Infof("Ignition provisioning: time=%v\n", ignProvisioning.ProvisioningDate) return nil } func logProvisioningInformation() { if err := logAlephInformation(); err != nil { - glog.Warningf("Failed to get aleph information: %v", err) + klog.Warningf("Failed to get aleph information: %v", err) } if err := logInitionProvisioning(); err != nil { - glog.Warningf("Failed to get Ignition provisioning information: %v", err) + klog.Warningf("Failed to get Ignition provisioning information: %v", err) } } diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index edc9db9ed5..33f163aa6e 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -18,7 +18,6 @@ import ( "time" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" "golang.org/x/time/rate" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -27,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" coreinformersv1 "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" + "k8s.io/klog/v2" corev1lister "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" @@ -261,7 +261,7 @@ func New( if err != nil { return nil, fmt.Errorf("error reading osImageURL from rpm-ostree: %w", err) } - glog.Infof("Booted osImageURL: %s (%s) %s", osImageURL, osVersion, osCommit) + klog.Infof("Booted osImageURL: %s (%s) %s", osImageURL, osVersion, osCommit) } bootID := "" @@ -374,7 +374,7 @@ func (dn *Daemon) HypershiftConnect( node, err := dn.kubeClient.CoreV1().Nodes().Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { - glog.Fatalf("Cannot fetch node object: %v", err) + klog.Fatalf("Cannot fetch node object: %v", err) } dn.node = node @@ -466,14 +466,14 @@ func (dn *Daemon) handleErr(err error, key interface{}) { // Exit if nodewriter is not initialized, used for Hypershift if dn.nodeWriter == nil { dn.updateErrorStateHypershift(err) - glog.Fatalf("Error handling node sync: %v", err) + klog.Fatalf("Error handling node sync: %v", err) } if err := dn.updateErrorState(err); err != nil { - glog.Errorf("Could not update annotation: %v", err) + klog.Errorf("Could not update annotation: %v", err) } // This is at V(2) since the updateErrorState() call above ends up logging too - glog.V(2).Infof("Error syncing node %v (retries %d): %v", key, dn.queue.NumRequeues(key), err) + klog.V(2).Infof("Error syncing node %v (retries %d): %v", key, dn.queue.NumRequeues(key), err) dn.queue.AddRateLimited(key) } @@ -502,7 +502,7 @@ func (dn *Daemon) updateErrorStateHypershift(err error) { constants.MachineConfigDaemonReasonAnnotationKey: truncatedErr, } if _, annoErr := dn.nodeWriter.SetAnnotations(annos); annoErr != nil { - glog.Fatalf("Error setting degraded annotation %v, original error %v", annoErr, err) + klog.Fatalf("Error setting degraded annotation %v, original error %v", annoErr, err) } } @@ -514,13 +514,13 @@ func (dn *Daemon) initializeNode() error { } // Some parts of the MCO dispatch on whether or not we're managing a control plane node if _, isControlPlane := dn.node.Labels[ctrlcommon.MasterLabel]; isControlPlane { - glog.Infof("Node %s is part of the control plane", dn.node.Name) + klog.Infof("Node %s is part of the control plane", dn.node.Name) if err := dn.initializeControlPlane(); err != nil { return err } dn.isControlPlane = true } else { - glog.Infof("Node %s is not labeled %s", dn.node.Name, ctrlcommon.MasterLabel) + klog.Infof("Node %s is not labeled %s", dn.node.Name, ctrlcommon.MasterLabel) } dn.nodeInitialized = true return nil @@ -528,9 +528,9 @@ func (dn *Daemon) initializeNode() error { func (dn *Daemon) syncNode(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing node %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing node %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing node %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing node %q (%v)", key, time.Since(startTime)) }() _, name, err := cache.SplitMetaNamespaceKey(key) @@ -545,7 +545,7 @@ func (dn *Daemon) syncNode(key string) error { node, err := dn.nodeLister.Get(name) if apierrors.IsNotFound(err) { - glog.V(2).Infof("node %v has been deleted", key) + klog.V(2).Infof("node %v has been deleted", key) return nil } if err != nil { @@ -553,14 +553,14 @@ func (dn *Daemon) syncNode(key string) error { } // Check for Deleted Node if node.DeletionTimestamp != nil { - glog.Infof("Node %s was deleted!", node.Name) + klog.Infof("Node %s was deleted!", node.Name) return nil } // Check for queued reboot. If we attempt to sync while waiting for a reboot, // it will cause the update to start again, so we skip the sync. if dn.rebootQueued { - glog.Infof("Node %s is queued for a reboot, skipping sync.", node.Name) + klog.Infof("Node %s is queued for a reboot, skipping sync.", node.Name) return nil } @@ -578,10 +578,10 @@ func (dn *Daemon) syncNode(key string) error { oldReason := dn.node.Annotations[constants.MachineConfigDaemonReasonAnnotationKey] newReason := node.Annotations[constants.MachineConfigDaemonReasonAnnotationKey] if oldState != newState { - glog.Infof("Transitioned from state: %v -> %v", oldState, newState) + klog.Infof("Transitioned from state: %v -> %v", oldState, newState) } if oldReason != newReason { - glog.Infof("Transitioned from degraded/unreconcilable reason %v -> %v", oldReason, newReason) + klog.Infof("Transitioned from degraded/unreconcilable reason %v -> %v", oldReason, newReason) } dn.node = node } @@ -620,7 +620,7 @@ func (dn *Daemon) syncNode(key string) error { // to stay in this state if dn.node.Annotations[constants.DesiredDrainerAnnotationKey] != "" && dn.node.Annotations[constants.DesiredDrainerAnnotationKey] != dn.node.Annotations[constants.LastAppliedDrainerAnnotationKey] { - glog.Infof("A previously requested drain has not yet completed. Waiting for machine-config-controller to finish draining node.") + klog.Infof("A previously requested drain has not yet completed. Waiting for machine-config-controller to finish draining node.") return nil } @@ -639,7 +639,7 @@ func (dn *Daemon) syncNode(key string) error { return err } } - glog.V(2).Infof("Node %s is already synced", node.Name) + klog.V(2).Infof("Node %s is already synced", node.Name) return nil } @@ -649,7 +649,7 @@ func (dn *Daemon) runPreflightConfigDriftCheck() error { // This allows skip behavior based upon the presence of // the forcefile: /run/machine-config-daemon-force. if forceFileExists() { - glog.Infof("Skipping preflight config drift check; %s present", constants.MachineConfigDaemonForceFile) + klog.Infof("Skipping preflight config drift check; %s present", constants.MachineConfigDaemonForceFile) return nil } @@ -662,11 +662,11 @@ func (dn *Daemon) runPreflightConfigDriftCheck() error { if err := dn.validateOnDiskState(currentOnDisk); err != nil { dn.nodeWriter.Eventf(corev1.EventTypeWarning, "PreflightConfigDriftCheckFailed", err.Error()) - glog.Errorf("Preflight config drift check failed: %v", err) + klog.Errorf("Preflight config drift check failed: %v", err) return &configDriftErr{err} } - glog.Infof("Preflight config drift check successful (took %s)", time.Since(start)) + klog.Infof("Preflight config drift check successful (took %s)", time.Since(start)) return nil } @@ -694,8 +694,8 @@ func (dn *Daemon) detectEarlySSHAccessesFromBoot() error { return err } if len(journalOutput) > 0 { - glog.Info("Detected a login session before the daemon took over on first boot") - glog.Infof("Applying annotation: %v", machineConfigDaemonSSHAccessAnnotationKey) + klog.Info("Detected a login session before the daemon took over on first boot") + klog.Infof("Applying annotation: %v", machineConfigDaemonSSHAccessAnnotationKey) if err := dn.applySSHAccessedAnnotation(); err != nil { return err } @@ -705,7 +705,7 @@ func (dn *Daemon) detectEarlySSHAccessesFromBoot() error { // RunHypershift is the entry point for the simplified Hypershift mode daemon func (dn *Daemon) RunHypershift(stopCh <-chan struct{}, exitCh <-chan error) error { - glog.Info("Starting MachineConfigDaemon - Hypershift") + klog.Info("Starting MachineConfigDaemon - Hypershift") signaled := make(chan struct{}) dn.InstallSignalHandler(signaled) @@ -724,7 +724,7 @@ func (dn *Daemon) RunHypershift(stopCh <-chan struct{}, exitCh <-chan error) err case err := <-exitCh: // This channel gets errors from auxiliary goroutines like loginmonitor and kubehealth // TODO we really shouldn't have any for hypershift - glog.Warningf("Got an error from auxiliary tools: %v", err) + klog.Warningf("Got an error from auxiliary tools: %v", err) } } } @@ -756,7 +756,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { } if node.Annotations[constants.DesiredDrainerAnnotationKey] != node.Annotations[constants.LastAppliedDrainerAnnotationKey] { // The controller has not yet performed our previous request - glog.Infof("The controller has not yet performed our previous drain/uncordon request %s", node.Annotations[constants.DesiredDrainerAnnotationKey]) + klog.Infof("The controller has not yet performed our previous drain/uncordon request %s", node.Annotations[constants.DesiredDrainerAnnotationKey]) return nil } if node.Annotations[constants.DesiredMachineConfigAnnotationKey] == "" || @@ -764,7 +764,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { // We have not yet been signaled to update, just return // This may cause issues because the desiredConfig here doesn't necessarily match the config in the configmap // TODO consider revisiting that - glog.V(4).Info("CurrentConfig == DesiredConfig in node annotations.") + klog.V(4).Info("CurrentConfig == DesiredConfig in node annotations.") return nil } @@ -818,7 +818,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { return fmt.Errorf("cannot decode desiredConfig from configmap data: %w", err) } - glog.Infof("Successfully read current/desired Config") + klog.Infof("Successfully read current/desired Config") // check update reconcilability mcDiff, err := reconcilable(¤tConfig, &desiredConfig) @@ -827,7 +827,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { } if mcDiff.isEmpty() { // No diff was detected. Check if we are in the right state. - glog.Infof("No diff detected. Assuming a previous update was completed. Checking on-disk state.") + klog.Infof("No diff detected. Assuming a previous update was completed. Checking on-disk state.") if err := dn.validateOnDiskState(&desiredConfig); err != nil { return fmt.Errorf("disk validation failed: %w", err) } @@ -835,7 +835,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { if node.Annotations[constants.CurrentMachineConfigAnnotationKey] == targetHash && node.Annotations[constants.DesiredDrainerAnnotationKey] == fmt.Sprintf("%s-%s", constants.DrainerStateUncordon, targetHash) { // We are in a done state - glog.Infof("The pod is in a completed state. Awaiting removal.") + klog.Infof("The pod is in a completed state. Awaiting removal.") return nil } // Assume an update is completed. Set node state to done. Also request an uncordon @@ -848,12 +848,12 @@ func (dn *Daemon) syncNodeHypershift(key string) error { if _, err := dn.nodeWriter.SetAnnotations(annos); err != nil { return fmt.Errorf("failed to set Done annotation on node: %w", err) } - glog.Infof("The pod has completed update. Awaiting removal.") + klog.Infof("The pod has completed update. Awaiting removal.") // TODO os.Exit here return nil } - glog.Infof("Update is reconcilable. Diff: %v", mcDiff) + klog.Infof("Update is reconcilable. Diff: %v", mcDiff) // This should be eventually de-duplicated with the update() function. oldIgnConfig, err := ctrlcommon.ParseAndConvertConfig(currentConfig.Spec.Config.Raw) @@ -889,7 +889,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { return fmt.Errorf("failed to set Done annotation on node: %w", err) } // Wait for a future sync to perform post-drain actions - glog.Info("Setting drain request via annotation to controller.") + klog.Info("Setting drain request via annotation to controller.") return nil } } @@ -909,12 +909,12 @@ func (dn *Daemon) syncNodeHypershift(key string) error { // Finally, once we are successful, we perform the necessary post config change action // TODO should be de-duplicated with update() if ctrlcommon.InSlice(postConfigChangeActionReboot, actions) { - glog.Info("Rebooting node") + klog.Info("Rebooting node") return dn.reboot(fmt.Sprintf("Node will reboot into config %s", desiredConfig.Name)) } if ctrlcommon.InSlice(postConfigChangeActionNone, actions) { - glog.Infof("Node has Desired Config %s, skipping reboot", desiredConfig.Name) + klog.Infof("Node has Desired Config %s, skipping reboot", desiredConfig.Name) } if ctrlcommon.InSlice(postConfigChangeActionReloadCrio, actions) { @@ -922,7 +922,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { if err := reloadService(serviceName); err != nil { return fmt.Errorf("could not apply update: reloading %s configuration failed. Error: %w", serviceName, err) } - glog.Infof("%s config reloaded successfully! Desired config %s has been applied, skipping reboot", serviceName, desiredConfig.Name) + klog.Infof("%s config reloaded successfully! Desired config %s has been applied, skipping reboot", serviceName, desiredConfig.Name) } // We are here, which means reboot was not needed to apply the configuration. @@ -936,7 +936,7 @@ func (dn *Daemon) syncNodeHypershift(key string) error { if _, err := dn.nodeWriter.SetAnnotations(annos); err != nil { return fmt.Errorf("failed to set Done annotation on node: %w", err) } - glog.Info("A rebootless update was completed.") + klog.Info("A rebootless update was completed.") return nil } @@ -945,15 +945,15 @@ func (dn *Daemon) RunOnceFrom(onceFrom string, skipReboot bool) error { dn.skipReboot = skipReboot configi, contentFrom, err := dn.senseAndLoadOnceFrom(onceFrom) if err != nil { - glog.Warningf("Unable to decipher onceFrom config type: %s", err) + klog.Warningf("Unable to decipher onceFrom config type: %s", err) return err } switch c := configi.(type) { case ign3types.Config: - glog.V(2).Info("Daemon running directly from Ignition") + klog.V(2).Info("Daemon running directly from Ignition") return dn.runOnceFromIgnition(c) case mcfgv1.MachineConfig: - glog.V(2).Info("Daemon running directly from MachineConfig") + klog.V(2).Info("Daemon running directly from MachineConfig") return dn.runOnceFromMachineConfig(c, contentFrom) } return fmt.Errorf("unsupported onceFrom type provided") @@ -997,7 +997,7 @@ func (dn *Daemon) RunFirstbootCompleteMachineconfig() error { return fmt.Errorf("failed to reboot for secondary in-place update") } - glog.Info("rpm-ostree has container feature") + klog.Info("rpm-ostree has container feature") // Start with an empty config, then add our *booted* osImageURL to // it, reflecting the current machine state. @@ -1053,7 +1053,7 @@ func (dn *Daemon) InstallSignalHandler(signaled chan struct{}) { updateActive := dn.updateActive dn.updateActiveLock.Unlock() if updateActive { - glog.Info("Got SIGTERM, but actively updating") + klog.Info("Got SIGTERM, but actively updating") } else { close(signaled) return @@ -1070,14 +1070,14 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error { logSystem("Starting to manage node: %s", dn.name) dn.LogSystemData() - glog.Info("Starting MachineConfigDaemon") - defer glog.Info("Shutting down MachineConfigDaemon") + klog.Info("Starting MachineConfigDaemon") + defer klog.Info("Shutting down MachineConfigDaemon") signaled := make(chan struct{}) dn.InstallSignalHandler(signaled) if dn.kubeletHealthzEnabled { - glog.Info("Enabling Kubelet Healthz Monitor") + klog.Info("Enabling Kubelet Healthz Monitor") go dn.runKubeletHealthzMonitor(stopCh, dn.exitCh) } @@ -1100,7 +1100,7 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error { return nil case err := <-exitCh: // This channel gets errors from auxiliary goroutines like loginmonitor and kubehealth - glog.Warningf("Got an error from auxiliary tools: %v", err) + klog.Warningf("Got an error from auxiliary tools: %v", err) } } } @@ -1134,8 +1134,8 @@ func (dn *Daemon) runLoginMonitor(stopCh <-chan struct{}, exitCh chan<- error) { } if l > 0 { line := strings.Split(string(buf), "\n")[0] - glog.Infof("Detected a new login session: %s", line) - glog.Infof("Login access is discouraged! Applying annotation: %v", machineConfigDaemonSSHAccessAnnotationKey) + klog.Infof("Detected a new login session: %s", line) + klog.Infof("Login access is discouraged! Applying annotation: %v", machineConfigDaemonSSHAccessAnnotationKey) if err := dn.applySSHAccessedAnnotation(); err != nil { exitCh <- err } @@ -1158,9 +1158,9 @@ func (dn *Daemon) applySSHAccessedAnnotation() error { // Called whenever the on-disk config has drifted from the current machineconfig. func (dn *Daemon) onConfigDrift(err error) { dn.nodeWriter.Eventf(corev1.EventTypeWarning, "ConfigDriftDetected", err.Error()) - glog.Error(err) + klog.Error(err) if err := dn.updateErrorState(err); err != nil { - glog.Errorf("Could not update annotation: %v", err) + klog.Errorf("Could not update annotation: %v", err) } } @@ -1245,7 +1245,7 @@ func (dn *Daemon) runKubeletHealthzMonitor(stopCh <-chan struct{}, exitCh chan<- } func (dn *Daemon) getHealth() error { - glog.V(2).Info("Kubelet health running") + klog.V(2).Info("Kubelet health running") ctx, cancel := context.WithTimeout(context.Background(), kubeletHealthzTimeout) defer cancel() @@ -1268,11 +1268,11 @@ func (dn *Daemon) getHealth() error { } if string(respData) != "ok" { - glog.Warningf("Kubelet Healthz Endpoint returned: %s", string(respData)) + klog.Warningf("Kubelet Healthz Endpoint returned: %s", string(respData)) return nil } - glog.V(2).Info("Kubelet health ok") + klog.V(2).Info("Kubelet health ok") return nil } @@ -1282,11 +1282,11 @@ func (dn *Daemon) getHealth() error { // likely to be a root cause. func (dn *Daemon) syncFinalizationFailureAnnotation(finalizeError string) error { if finalizeError != "" { - glog.Warningf("Failed to finalize previous deployment: %s", finalizeError) + klog.Warningf("Failed to finalize previous deployment: %s", finalizeError) // Truncate this to a reasonable size in case it's somehow very long finalizeError = fmt.Sprintf("%.2000s", finalizeError) } else { - glog.Infof("Previous boot ostree-finalize-staged.service appears successful") + klog.Infof("Previous boot ostree-finalize-staged.service appears successful") } // Cache it globally so we can include it in any other error messages if applicable @@ -1339,7 +1339,7 @@ func (dn *Daemon) getStateAndConfigs(pendingConfigName string) (*stateAndConfigs // doesn't exist, we must not be bootstrapping } else { bootstrapping = true - glog.Info("In bootstrap mode") + klog.Info("In bootstrap mode") } currentConfigName, err := getNodeAnnotation(dn.node, constants.CurrentMachineConfigAnnotationKey) @@ -1370,7 +1370,7 @@ func (dn *Daemon) getStateAndConfigs(pendingConfigName string) (*stateAndConfigs if dn.NodeUpdaterClient != nil { finalizeError, err := dn.NodeUpdaterClient.Peel().QueryPreviousDeploymentError() if err != nil { - glog.Warningf("failed to query for deployment failure: %v", err) + klog.Warningf("failed to query for deployment failure: %v", err) } else { var finalizeErrorVal string if finalizeError != nil { @@ -1383,17 +1383,17 @@ func (dn *Daemon) getStateAndConfigs(pendingConfigName string) (*stateAndConfigs var desiredConfig *mcfgv1.MachineConfig if currentConfigName == desiredConfigName { desiredConfig = currentConfig - glog.Infof("Current+desired config: %s", currentConfigName) + klog.Infof("Current+desired config: %s", currentConfigName) } else { desiredConfig, err = dn.mcLister.Get(desiredConfigName) if err != nil { return nil, err } - glog.Infof("Current config: %s", currentConfigName) - glog.Infof("Desired config: %s", desiredConfigName) + klog.Infof("Current config: %s", currentConfigName) + klog.Infof("Desired config: %s", desiredConfigName) } - glog.Infof("state: %s", state) + klog.Infof("state: %s", state) var pendingConfig *mcfgv1.MachineConfig // We usually expect that if current != desired, pending == desired; however, @@ -1413,7 +1413,7 @@ func (dn *Daemon) getStateAndConfigs(pendingConfigName string) (*stateAndConfigs if state == constants.MachineConfigDaemonStateDegraded { degradedReason, err = getNodeAnnotation(dn.node, constants.MachineConfigDaemonReasonAnnotationKey) if err != nil { - glog.Errorf("Could not retrieve degraded reason. err: %v", err) + klog.Errorf("Could not retrieve degraded reason. err: %v", err) } } @@ -1436,18 +1436,18 @@ func (dn *Daemon) LogSystemData() { if dn.os.IsCoreOSVariant() { out, err := runGetOut("rpm-ostree", "status") if err != nil { - glog.Fatalf("unable to get rpm-ostree status: %s", err) + klog.Fatalf("unable to get rpm-ostree status: %s", err) } - glog.Infof("%s", out) + klog.Infof("%s", out) logProvisioningInformation() } boots, err := runGetOut("journalctl", "--list-boots") if err != nil { - glog.Errorf("Listing boots: %v", err) + klog.Errorf("Listing boots: %v", err) } - glog.Infof("journalctl --list-boots:\n" + string(boots)) + klog.Infof("journalctl --list-boots:\n" + string(boots)) // Since nothing in the cluster today watches systemd units, let's // at least capture them in our logs to start. See also @@ -1458,11 +1458,11 @@ func (dn *Daemon) LogSystemData() { // also xref https://github.com/coreos/console-login-helper-messages/blob/e8a849f4c23910e7c556c10719911cc59873fc23/usr/share/console-login-helper-messages/profile.sh failedServices, err := runGetOut("systemctl", "list-units", "--state=failed", "--no-legend") if err != nil { - glog.Errorf("Listing failed systemd services: %v", err) + klog.Errorf("Listing failed systemd services: %v", err) } else if len(failedServices) > 0 { - glog.Infof("systemctl --failed:\n" + string(failedServices)) + klog.Infof("systemctl --failed:\n" + string(failedServices)) } else { - glog.Info("systemd service state: OK") + klog.Info("systemd service state: OK") } } @@ -1541,7 +1541,7 @@ func (dn *Daemon) storeCurrentConfigOnDisk(current *mcfgv1.MachineConfig) error func upgradeHackFor44AndBelow() error { _, err := os.Stat(constants.MachineConfigEncapsulatedPath) if err == nil { - glog.Warningf("Failed to complete machine-config-daemon-firstboot before joining cluster!") + klog.Warningf("Failed to complete machine-config-daemon-firstboot before joining cluster!") // Removing this file signals completion of the initial MC processing. if err := os.Rename(constants.MachineConfigEncapsulatedPath, constants.MachineConfigEncapsulatedBakPath); err != nil { return fmt.Errorf("failed to rename encapsulated MachineConfig after processing on firstboot: %w", err) @@ -1585,14 +1585,14 @@ func PersistNetworkInterfaces(osRoot string) error { // nmstate always logs to stderr, so we need to capture/forward that too cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - glog.Infof("Running: %s", strings.Join(cmd.Args, " ")) + klog.Infof("Running: %s", strings.Join(cmd.Args, " ")) if err := cmd.Run(); err != nil { return fmt.Errorf("failed to run nmstatectl: %w", err) } } else if hostos.IsEL9() { ifnames, err := getIfnamesFromLinkFiles(osRoot) if err != nil { - glog.Warningf("Failed to persist NIC names: %v", err) + klog.Warningf("Failed to persist NIC names: %v", err) return nil } @@ -1680,14 +1680,14 @@ func (dn *Daemon) isSSHKeyLocationUpdateRequired() (bool, error) { // Decode the Ignition config and perform the SSH key update. func (dn *Daemon) updateSSHKeyLocation(cfg *mcfgv1.MachineConfig) error { - glog.Infof("SSH key location update required. Moving SSH keys from %q to %q.", constants.RHCOS8SSHKeyPath, constants.RHCOS9SSHKeyPath) + klog.Infof("SSH key location update required. Moving SSH keys from %q to %q.", constants.RHCOS8SSHKeyPath, constants.RHCOS9SSHKeyPath) ignConfig, err := ctrlcommon.ParseAndConvertConfig(cfg.Spec.Config.Raw) if err != nil { return fmt.Errorf("ignition failure when updating SSH key location: %w", err) } - if err := dn.updateSSHKeys(ignConfig.Passwd.Users, ignConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(ignConfig.Passwd.Users); err != nil { return fmt.Errorf("could not write SSH keys to new location: %w", err) } @@ -1703,7 +1703,7 @@ func (dn *Daemon) updateSSHKeyLocationIfNeeded(cfg *mcfgv1.MachineConfig) error } if !sshKeyLocationUpdateRequired { - glog.Infof("SSH key location (%q) up-to-date!", constants.RHCOS9SSHKeyPath) + klog.Infof("SSH key location (%q) up-to-date!", constants.RHCOS9SSHKeyPath) return nil } @@ -1843,19 +1843,8 @@ func (dn *Daemon) checkStateOnFirstRun() error { // // In the case where we're booting a node for the first time, or the MCD // is restarted, that will be the current config. - // - // In the case where we have - // a pending config, this is where we validate that it actually applied. - // We currently just do this on startup, but in the future it could e.g. be - // a once-a-day or week cron job. - var expectedConfig *mcfgv1.MachineConfig - if state.pendingConfig != nil { - glog.Infof("Validating against pending config %s", state.pendingConfig.GetName()) - expectedConfig = state.pendingConfig - } else { - glog.Infof("Validating against current config %s", state.currentConfig.GetName()) - expectedConfig = state.currentConfig - } + + klog.Infof("Validating against current config %s", state.currentConfig.GetName()) if forceFileExists() { logSystem("Skipping on-disk validation; %s present", constants.MachineConfigDaemonForceFile) @@ -1907,19 +1896,28 @@ func (dn *Daemon) updateConfigAndState(state *stateAndConfigs) (bool, error) { } } + // Set the current config to the last written config to disk. This will be the last + // "successful" config update we have completed. + currentOnDisk, err := dn.getCurrentConfigOnDisk() + if err == nil { + state.currentConfig = currentOnDisk + } else { + klog.Infof("Error reading config from disk") + return false, fmt.Errorf("error reading config from disk: %w", err) + } + // In case of node reboot, it may be the case that desiredConfig changed while we // were coming up, so we next look at that before uncordoning the node (so // we don't uncordon and then immediately re-cordon) inDesiredConfig := state.currentConfig.GetName() == state.desiredConfig.GetName() if inDesiredConfig { - if state.pendingConfig != nil { - // Great, we've successfully rebooted for the desired config, - // let's mark it done! - glog.Infof("Completing pending config %s", state.pendingConfig.GetName()) - if err := dn.completeUpdate(state.pendingConfig.GetName()); err != nil { - UpdateStateMetric(mcdUpdateState, "", err.Error()) - return inDesiredConfig, err - } + // Great, we've successfully rebooted for the desired config, + // let's mark it done! + klog.Infof("Completing update to target config %s", state.currentConfig.GetName()) + if err := dn.completeUpdate(state.currentConfig.GetName()); err != nil { + UpdateStateMetric(mcdUpdateState, "", err.Error()) + return inDesiredConfig, err + } // We update the node annotation, delete the state file, etc. if dn.nodeWriter != nil { @@ -1943,7 +1941,7 @@ func (dn *Daemon) updateConfigAndState(state *stateAndConfigs) (bool, error) { } } - glog.Infof("In desired config %s", state.currentConfig.GetName()) + klog.Infof("In desired config %s", state.currentConfig.GetName()) UpdateStateMetric(mcdUpdateState, state.currentConfig.GetName(), "") } @@ -2010,7 +2008,7 @@ func (dn *Daemon) runOnceFromIgnition(ignConfig ign3types.Config) error { func (dn *Daemon) handleNodeEvent(node interface{}) { n := node.(*corev1.Node) - glog.V(4).Infof("Updating Node %s", n.Name) + klog.V(4).Infof("Updating Node %s", n.Name) dn.enqueueNode(n) } @@ -2054,11 +2052,11 @@ func (dn *Daemon) prepUpdateFromCluster() (*mcfgv1.MachineConfig, *mcfgv1.Machin if desiredConfigName == currentConfigName { if state == constants.MachineConfigDaemonStateDone { // No actual update to the config - glog.V(2).Info("No updating is required") + klog.V(2).Info("No updating is required") return nil, nil, nil } // This seems like it shouldn't happen...let's just warn for now. - glog.Warningf("current+desiredConfig is %s but state is %s", currentConfigName, state) + klog.Warningf("current+desiredConfig is %s but state is %s", currentConfigName, state) } return currentConfig, desiredConfig, nil } @@ -2074,7 +2072,7 @@ func (dn *Daemon) completeUpdate(desiredConfigName string) error { if err := wait.Poll(10*time.Second, 10*time.Minute, func() (bool, error) { node, err := dn.kubeClient.CoreV1().Nodes().Get(context.TODO(), dn.name, metav1.GetOptions{}) if err != nil { - glog.Warningf("Failed to get node: %v", err) + klog.Warningf("Failed to get node: %v", err) return false, nil } if node.Annotations[constants.DesiredDrainerAnnotationKey] != node.Annotations[constants.LastAppliedDrainerAnnotationKey] { @@ -2152,13 +2150,13 @@ func (dn *CoreOSDaemon) validateKernelArguments(currentConfig *mcfgv1.MachineCon if len(missing) > 0 { cmdlinebytes, err := os.ReadFile(CmdLineFile) if err != nil { - glog.Warningf("Failed to read %s: %v", CmdLineFile, err) + klog.Warningf("Failed to read %s: %v", CmdLineFile, err) } else { - glog.Infof("Booted command line: %s", string(cmdlinebytes)) + klog.Infof("Booted command line: %s", string(cmdlinebytes)) } - glog.Infof("Current ostree kargs: %s", rpmostreeKargs) - glog.Infof("Expected MachineConfig kargs: %v", expected) - return fmt.Errorf("Missing expected kernel arguments: %v", missing) + klog.Infof("Current ostree kargs: %s", rpmostreeKargs) + klog.Infof("Expected MachineConfig kargs: %v", expected) + return fmt.Errorf("missing expected kernel arguments: %v", missing) } return nil } @@ -2209,7 +2207,7 @@ func (dn *Daemon) validateOnDiskState(currentConfig *mcfgv1.MachineConfig) error func (dn *Daemon) checkOS(osImageURL string) bool { // Nothing to do if we're not on RHCOS or FCOS if !dn.os.IsCoreOSVariant() { - glog.Infof(`Not booted into a CoreOS variant, ignoring target OSImageURL %s`, osImageURL) + klog.Infof(`Not booted into a CoreOS variant, ignoring target OSImageURL %s`, osImageURL) return true } @@ -2217,10 +2215,10 @@ func (dn *Daemon) checkOS(osImageURL string) bool { // so I'm wondering if at one point this used to work this way.... inspection, _, err := imageInspect(osImageURL) if err != nil { - glog.Warningf("Unable to check manifest for matching hash: %s", err) + klog.Warningf("Unable to check manifest for matching hash: %s", err) } else if ostreeCommit, ok := inspection.Labels["ostree.commit"]; ok { if ostreeCommit == dn.bootedOSCommit { - glog.Infof("We are technically in the right image even if the URL doesn't match (%s == %s)", ostreeCommit, osImageURL) + klog.Infof("We are technically in the right image even if the URL doesn't match (%s == %s)", ostreeCommit, osImageURL) return true } } @@ -2282,16 +2280,16 @@ func (dn *Daemon) senseAndLoadOnceFrom(onceFrom string) (interface{}, onceFromOr // Try each supported parser ignConfig, err := ctrlcommon.ParseAndConvertConfig(content) if err == nil && ignConfig.Ignition.Version != "" { - glog.V(2).Info("onceFrom file is of type Ignition") + klog.V(2).Info("onceFrom file is of type Ignition") return ignConfig, contentFrom, nil } - glog.V(2).Infof("%s is not an Ignition config: %v\nTrying MachineConfig.", onceFrom, err) + klog.V(2).Infof("%s is not an Ignition config: %v\nTrying MachineConfig.", onceFrom, err) // Try to parse as a machine config mc, err := mcoResourceRead.ReadMachineConfigV1(content) if err == nil && mc != nil { - glog.V(2).Info("onceFrom file is of type MachineConfig") + klog.V(2).Info("onceFrom file is of type MachineConfig") return *mc, contentFrom, nil } diff --git a/pkg/daemon/drain.go b/pkg/daemon/drain.go index 854fd7d683..7e4a230c7e 100644 --- a/pkg/daemon/drain.go +++ b/pkg/daemon/drain.go @@ -9,12 +9,12 @@ import ( "github.com/BurntSushi/toml" "github.com/containers/image/v5/pkg/sysregistriesv2" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/daemon/constants" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/klog/v2" ) func (dn *Daemon) drainRequired() bool { @@ -72,7 +72,7 @@ func (dn *Daemon) performDrain() error { if err := wait.Poll(10*time.Second, 1*time.Hour, func() (bool, error) { node, err := dn.kubeClient.CoreV1().Nodes().Get(context.TODO(), dn.name, metav1.GetOptions{}) if err != nil { - glog.Warningf("Failed to get node: %v", err) + klog.Warningf("Failed to get node: %v", err) return false, nil } if node.Annotations[constants.DesiredDrainerAnnotationKey] != node.Annotations[constants.LastAppliedDrainerAnnotationKey] { @@ -90,7 +90,7 @@ func (dn *Daemon) performDrain() error { logSystem("drain complete") t := time.Since(startTime).Seconds() - glog.Infof("Successful drain took %v seconds", t) + klog.Infof("Successful drain took %v seconds", t) return nil } @@ -182,7 +182,7 @@ func isSafeContainerRegistryConfChanges(oldIgnConfig, newIgnConfig ign3types.Con for regLoc := range oldRegHashMap { _, ok := newRegHashMap[regLoc] if !ok { - glog.Infof("%s: registry %s has been removed", constants.ContainerRegistryConfPath, regLoc) + klog.Infof("%s: registry %s has been removed", constants.ContainerRegistryConfPath, regLoc) return false, nil } } @@ -196,22 +196,22 @@ func isSafeContainerRegistryConfChanges(oldIgnConfig, newIgnConfig ign3types.Con // Registry has been changed in the new config. // Check that changes made are safe or not. if oldReg.Prefix != newReg.Prefix { - glog.Infof("%s: prefix value for registry %s has changed from %s to %s", + klog.Infof("%s: prefix value for registry %s has changed from %s to %s", constants.ContainerRegistryConfPath, regLoc, oldReg.Prefix, newReg.Prefix) return false, nil } if oldReg.Location != newReg.Location { - glog.Infof("%s: location value for registry %s has changed from %s to %s", + klog.Infof("%s: location value for registry %s has changed from %s to %s", constants.ContainerRegistryConfPath, regLoc, oldReg.Location, newReg.Location) return false, nil } if oldReg.Blocked != newReg.Blocked { - glog.Infof("%s: blocked value for registry %s has changed from %t to %t", + klog.Infof("%s: blocked value for registry %s has changed from %t to %t", constants.ContainerRegistryConfPath, regLoc, oldReg.Blocked, newReg.Blocked) return false, nil } if oldReg.Insecure != newReg.Insecure { - glog.Infof("%s: insecure value for registry %s has changed from %t to %t", + klog.Infof("%s: insecure value for registry %s has changed from %t to %t", constants.ContainerRegistryConfPath, regLoc, oldReg.Insecure, newReg.Insecure) return false, nil } @@ -219,7 +219,7 @@ func isSafeContainerRegistryConfChanges(oldIgnConfig, newIgnConfig ign3types.Con // Ensure that all the old mirrors are present for _, m := range oldReg.Mirrors { if found, _ := searchRegistryMirror(m.Location, newReg.Mirrors); !found { - glog.Infof("%s: mirror %s has been removed in registry %s", + klog.Infof("%s: mirror %s has been removed in registry %s", constants.ContainerRegistryConfPath, m.Location, regLoc) return false, nil } @@ -228,7 +228,7 @@ func isSafeContainerRegistryConfChanges(oldIgnConfig, newIgnConfig ign3types.Con // Ensure that any change to current does not unset pull-from-mirror="digest-only" if found, oldMirror := searchRegistryMirror(m.Location, oldReg.Mirrors); found { if m.PullFromMirror != oldMirror.PullFromMirror && m.PullFromMirror != sysregistriesv2.MirrorByDigestOnly { - glog.Infof("%s: pull-from-mirror value for mirror %s has changed from %s to %s ", + klog.Infof("%s: pull-from-mirror value for mirror %s has changed from %s to %s ", constants.ContainerRegistryConfPath, m.Location, oldMirror.PullFromMirror, m.PullFromMirror) return false, nil } @@ -236,7 +236,7 @@ func isSafeContainerRegistryConfChanges(oldIgnConfig, newIgnConfig ign3types.Con // Ensure that any added mirror has set pull-from-mirror="digest-only" if found, _ := searchRegistryMirror(m.Location, oldReg.Mirrors); !found { if m.PullFromMirror != sysregistriesv2.MirrorByDigestOnly && !newReg.MirrorByDigestOnly { - glog.Infof("%s: mirror %s has been added in registry %s that has pull-from-mirror set to %s ", + klog.Infof("%s: mirror %s has been added in registry %s that has pull-from-mirror set to %s ", constants.ContainerRegistryConfPath, m.Location, regLoc, m.PullFromMirror) return false, nil } @@ -246,13 +246,13 @@ func isSafeContainerRegistryConfChanges(oldIgnConfig, newIgnConfig ign3types.Con } } else if !allDigestOnlyMirror(newReg) { // Ensure that each mirror under the newReg has pull-from-mirror=digest-only - glog.Infof("%s: registry %s has been added with mirror does not set pull-from-mirror=digest-only", + klog.Infof("%s: registry %s has been added with mirror does not set pull-from-mirror=digest-only", constants.ContainerRegistryConfPath, regLoc) return false, nil } } - glog.Infof("%s: changes made are safe to skip drain", constants.ContainerRegistryConfPath) + klog.Infof("%s: changes made are safe to skip drain", constants.ContainerRegistryConfPath) return true, nil } diff --git a/pkg/daemon/file_writers.go b/pkg/daemon/file_writers.go index d9b9ef1714..c116ae8297 100644 --- a/pkg/daemon/file_writers.go +++ b/pkg/daemon/file_writers.go @@ -10,8 +10,8 @@ import ( "strconv" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" "github.com/google/renameio" + "k8s.io/klog/v2" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" ) @@ -120,21 +120,21 @@ func writeDropins(u ign3types.Unit, systemdRoot string, isCoreOSVariant bool) er for i := range u.Dropins { dpath := filepath.Join(systemdRoot, u.Name+".d", u.Dropins[i].Name) if u.Dropins[i].Contents == nil || *u.Dropins[i].Contents == "" { - glog.Infof("Dropin for %s has no content, skipping write", u.Dropins[i].Name) + klog.Infof("Dropin for %s has no content, skipping write", u.Dropins[i].Name) if _, err := os.Stat(dpath); err != nil { if os.IsNotExist(err) { continue } return err } - glog.Infof("Removing %q, updated file has zero length", dpath) + klog.Infof("Removing %q, updated file has zero length", dpath) if err := os.Remove(dpath); err != nil { return err } continue } - glog.Infof("Writing systemd unit dropin %q", u.Dropins[i].Name) + klog.Infof("Writing systemd unit dropin %q", u.Dropins[i].Name) if _, err := os.Stat(withUsrPath(dpath)); err == nil && isCoreOSVariant { if err := createOrigFile(withUsrPath(dpath), dpath); err != nil { @@ -145,7 +145,7 @@ func writeDropins(u ign3types.Unit, systemdRoot string, isCoreOSVariant bool) er return fmt.Errorf("failed to write systemd unit dropin %q: %w", u.Dropins[i].Name, err) } - glog.V(2).Infof("Wrote systemd unit dropin at %s", dpath) + klog.V(2).Infof("Wrote systemd unit dropin at %s", dpath) } return nil @@ -157,10 +157,10 @@ func writeFiles(files []ign3types.File, skipCertificateWrite bool) error { for _, file := range files { if skipCertificateWrite && file.Path == caBundleFilePath { // TODO remove this special case once we have a better way to do this - glog.V(4).Infof("Skipping file %s during writeFiles", caBundleFilePath) + klog.V(4).Infof("Skipping file %s during writeFiles", caBundleFilePath) continue } - glog.Infof("Writing file %q", file.Path) + klog.Infof("Writing file %q", file.Path) // We don't support appends in the file section, so instead of waiting to fail validation, // let's explicitly fail here. @@ -204,23 +204,23 @@ func writeUnit(u ign3types.Unit, systemdRoot string, isCoreOSVariant bool) error if u.Mask != nil && *u.Mask { // if the unit is masked, symlink fpath to /dev/null and return early. - glog.V(2).Info("Systemd unit masked") + klog.V(2).Info("Systemd unit masked") if err := os.RemoveAll(fpath); err != nil { return fmt.Errorf("failed to remove unit %q: %w", u.Name, err) } - glog.V(2).Infof("Removed unit %q", u.Name) + klog.V(2).Infof("Removed unit %q", u.Name) if err := renameio.Symlink(pathDevNull, fpath); err != nil { return fmt.Errorf("failed to symlink unit %q to %s: %w", u.Name, pathDevNull, err) } - glog.V(2).Infof("Created symlink unit %q to %s", u.Name, pathDevNull) + klog.V(2).Infof("Created symlink unit %q to %s", u.Name, pathDevNull) // Return early since we don't need to write the file contents in this case. return nil } if u.Contents != nil && *u.Contents != "" { - glog.Infof("Writing systemd unit %q", u.Name) + klog.Infof("Writing systemd unit %q", u.Name) if _, err := os.Stat(withUsrPath(fpath)); err == nil && isCoreOSVariant { if err := createOrigFile(withUsrPath(fpath), fpath); err != nil { @@ -231,14 +231,14 @@ func writeUnit(u ign3types.Unit, systemdRoot string, isCoreOSVariant bool) error return fmt.Errorf("failed to write systemd unit %q: %w", u.Name, err) } - glog.V(2).Infof("Successfully wrote systemd unit %q: ", u.Name) + klog.V(2).Infof("Successfully wrote systemd unit %q: ", u.Name) } else if u.Mask != nil && !*u.Mask { // if mask is explicitly set to false, make sure to remove a previous mask // see https://bugzilla.redhat.com/show_bug.cgi?id=1966445 // Note that this does not catch all cleanup cases; for example, if the previous machine config specified // Contents, and the current one does not, the previous content will not get cleaned up. For now we're ignoring some // of those edge cases rather than introducing more complexity. - glog.V(2).Infof("Ensuring systemd unit %q has no mask at %q", u.Name, fpath) + klog.V(2).Infof("Ensuring systemd unit %q has no mask at %q", u.Name, fpath) if err := os.RemoveAll(fpath); err != nil { return fmt.Errorf("failed to cleanup %s: %w", fpath, err) } @@ -263,7 +263,7 @@ func lookupUID(username string) (int, error) { if err != nil { return 0, fmt.Errorf("failed to retrieve UserID for username: %s", username) } - glog.V(2).Infof("Retrieved UserId: %s for username: %s", osUser.Uid, username) + klog.V(2).Infof("Retrieved UserId: %s for username: %s", osUser.Uid, username) uid, _ := strconv.Atoi(osUser.Uid) return uid, nil } @@ -273,7 +273,7 @@ func lookupGID(group string) (int, error) { if err != nil { return 0, fmt.Errorf("failed to retrieve GroupID for group: %v", group) } - glog.V(2).Infof("Retrieved GroupID: %s for group: %s", osGroup.Gid, group) + klog.V(2).Infof("Retrieved GroupID: %s for group: %s", osGroup.Gid, group) gid, _ := strconv.Atoi(osGroup.Gid) return gid, nil } diff --git a/pkg/daemon/kernelargs.go b/pkg/daemon/kernelargs.go index a07a21faaa..7cd41581f8 100644 --- a/pkg/daemon/kernelargs.go +++ b/pkg/daemon/kernelargs.go @@ -10,9 +10,9 @@ import ( // Enable sha256 in container image references _ "crypto/sha256" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/pkg/daemon/osrelease" "github.com/openshift/machine-config-operator/pkg/daemon/pivot/types" + "k8s.io/klog/v2" ) const ( @@ -103,10 +103,10 @@ func parseTuningFile(tuningFilePath, cmdLinePath string) ([]types.TuneArgument, if !inUse { addArguments = append(addArguments, types.TuneArgument{Key: key, Bare: true}) } else { - glog.Infof(`skipping "%s" as it is already in use`, key) + klog.Infof(`skipping "%s" as it is already in use`, key) } } else { - glog.Infof("%s not an allowlisted kernel argument", key) + klog.Infof("%s not an allowlisted kernel argument", key) } } else if strings.HasPrefix(line, "DELETE ") { // NOTE: Today only specific bare kernel arguments are allowed so @@ -124,13 +124,13 @@ func parseTuningFile(tuningFilePath, cmdLinePath string) ([]types.TuneArgument, if inUse { deleteArguments = append(deleteArguments, types.TuneArgument{Key: key, Bare: true}) } else { - glog.Infof(`skipping "%s" as it is not present in the current argument list`, key) + klog.Infof(`skipping "%s" as it is not present in the current argument list`, key) } } else { - glog.Infof("%s not an allowlisted kernel argument", key) + klog.Infof("%s not an allowlisted kernel argument", key) } } else { - glog.V(2).Infof(`skipping malformed line in %s: "%s"`, tuningFilePath, line) + klog.V(2).Infof(`skipping malformed line in %s: "%s"`, tuningFilePath, line) } } return addArguments, deleteArguments, nil @@ -173,7 +173,7 @@ func UpdateTuningArgs(tuningFilePath, cmdLinePath string) error { } if changed { - glog.Info("Updated kernel tuning arguments") + klog.Info("Updated kernel tuning arguments") } return nil } diff --git a/pkg/daemon/node.go b/pkg/daemon/node.go index 6121f9ae63..c782cc47a8 100644 --- a/pkg/daemon/node.go +++ b/pkg/daemon/node.go @@ -5,9 +5,9 @@ import ( "fmt" "os" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/pkg/daemon/constants" corev1 "k8s.io/api/core/v1" + "k8s.io/klog/v2" ) func (dn *Daemon) loadNodeAnnotations(node *corev1.Node) (*corev1.Node, error) { @@ -20,7 +20,7 @@ func (dn *Daemon) loadNodeAnnotations(node *corev1.Node) (*corev1.Node, error) { return node, nil } - glog.Infof("No %s annotation on node %s: %v, in cluster bootstrap, loading initial node annotation from %s", constants.CurrentMachineConfigAnnotationKey, node.Name, node.Annotations, constants.InitialNodeAnnotationsFilePath) + klog.Infof("No %s annotation on node %s: %v, in cluster bootstrap, loading initial node annotation from %s", constants.CurrentMachineConfigAnnotationKey, node.Name, node.Annotations, constants.InitialNodeAnnotationsFilePath) d, err := os.ReadFile(constants.InitialNodeAnnotationsFilePath) if err != nil && !os.IsNotExist(err) { @@ -30,7 +30,7 @@ func (dn *Daemon) loadNodeAnnotations(node *corev1.Node) (*corev1.Node, error) { // try currentConfig if, for whatever reason we lost annotations? this is super best effort. currentOnDisk, err := dn.getCurrentConfigOnDisk() if err == nil { - glog.Infof("Setting initial node config based on current configuration on disk: %s", currentOnDisk.GetName()) + klog.Infof("Setting initial node config based on current configuration on disk: %s", currentOnDisk.GetName()) return dn.nodeWriter.SetAnnotations(map[string]string{constants.CurrentMachineConfigAnnotationKey: currentOnDisk.GetName()}) } return nil, err @@ -41,7 +41,7 @@ func (dn *Daemon) loadNodeAnnotations(node *corev1.Node) (*corev1.Node, error) { return nil, fmt.Errorf("failed to unmarshal initial annotations: %w", err) } - glog.Infof("Setting initial node config: %s", initial[constants.CurrentMachineConfigAnnotationKey]) + klog.Infof("Setting initial node config: %s", initial[constants.CurrentMachineConfigAnnotationKey]) node, err = dn.nodeWriter.SetAnnotations(initial) if err != nil { return nil, fmt.Errorf("failed to set initial annotations: %w", err) diff --git a/pkg/daemon/on_disk_validation.go b/pkg/daemon/on_disk_validation.go index 2ed42388c1..a8b4cbb4ea 100644 --- a/pkg/daemon/on_disk_validation.go +++ b/pkg/daemon/on_disk_validation.go @@ -8,10 +8,10 @@ import ( ign2types "github.com/coreos/ignition/config/v2_2/types" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" "github.com/google/go-cmp/cmp" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" + "k8s.io/klog/v2" ) // Validates that the on-disk state matches a given MachineConfig. @@ -176,7 +176,7 @@ func checkV3Files(files []ign3types.File) error { for _, f := range files { if f.Path == caBundleFilePath { // TODO remove this special case once we have a better way to do this - glog.V(4).Infof("Skipping file %s during checkV3Files", caBundleFilePath) + klog.V(4).Infof("Skipping file %s during checkV3Files", caBundleFilePath) continue } if len(f.Append) > 0 { @@ -242,7 +242,7 @@ func checkFileContentsAndMode(filePath string, expectedContent []byte, mode os.F return fmt.Errorf("could not read file %q: %w", filePath, err) } if !bytes.Equal(contents, expectedContent) { - glog.Errorf("content mismatch for file %q (-want +got):\n%s", filePath, cmp.Diff(expectedContent, contents)) + klog.Errorf("content mismatch for file %q (-want +got):\n%s", filePath, cmp.Diff(expectedContent, contents)) return fmt.Errorf("content mismatch for file %q", filePath) } return nil diff --git a/pkg/daemon/pivot/utils/run.go b/pkg/daemon/pivot/utils/run.go index 65f8c326b6..bac482366b 100644 --- a/pkg/daemon/pivot/utils/run.go +++ b/pkg/daemon/pivot/utils/run.go @@ -9,14 +9,14 @@ import ( "strings" "time" - "github.com/golang/glog" kubeErrs "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/klog/v2" ) // runImpl is the actual shell execution implementation used by other functions. func runImpl(command string, args ...string) ([]byte, error) { - glog.Infof("Running: %s %s\n", command, strings.Join(args, " ")) + klog.Infof("Running: %s %s\n", command, strings.Join(args, " ")) cmd := exec.Command(command, args...) // multiplex writes to std streams so we keep seeing logs in MCD/systemd // but we'll still be able to give out something here @@ -42,7 +42,7 @@ func runExtBackoff(backoff wait.Backoff, command string, args ...string) (string out, err := runImpl(command, args...) if err != nil { lastErr = err - glog.Warningf("%s failed: %v; retrying...", command, err) + klog.Warningf("%s failed: %v; retrying...", command, err) return false, nil } output = strings.TrimSpace(string(out)) diff --git a/pkg/daemon/rpm-ostree.go b/pkg/daemon/rpm-ostree.go index e9d44f6af2..82db50789e 100644 --- a/pkg/daemon/rpm-ostree.go +++ b/pkg/daemon/rpm-ostree.go @@ -12,10 +12,10 @@ import ( "github.com/containers/image/v5/types" rpmostreeclient "github.com/coreos/rpmostree-client-go/pkg/client" - "github.com/golang/glog" "github.com/opencontainers/go-digest" pivotutils "github.com/openshift/machine-config-operator/pkg/daemon/pivot/utils" "gopkg.in/yaml.v2" + "k8s.io/klog/v2" ) const ( @@ -82,7 +82,7 @@ InaccessiblePaths= if err := runCmdSync("systemctl", "daemon-reload"); err != nil { return err } - glog.Infof("Enabled workaround for bug 2111817") + klog.Infof("Enabled workaround for bug 2111817") return nil } @@ -205,19 +205,19 @@ func (r *RpmOstreeClient) Rebase(imgURL, osImageContentDir string) (changed bool if len(defaultDeployment.CustomOrigin) > 0 { if strings.HasPrefix(defaultDeployment.CustomOrigin[0], "pivot://") { previousPivot = defaultDeployment.CustomOrigin[0][len("pivot://"):] - glog.Infof("Previous pivot: %s", previousPivot) + klog.Infof("Previous pivot: %s", previousPivot) } else { - glog.Infof("Previous custom origin: %s", defaultDeployment.CustomOrigin[0]) + klog.Infof("Previous custom origin: %s", defaultDeployment.CustomOrigin[0]) } } else { - glog.Info("Current origin is not custom") + klog.Info("Current origin is not custom") } var imageData *types.ImageInspectInfo if imageData, _, err = imageInspect(imgURL); err != nil { if err != nil { var podmanImgData *imageInspection - glog.Infof("Falling back to using podman inspect") + klog.Infof("Falling back to using podman inspect") if podmanImgData, err = podmanInspect(imgURL); err != nil { return } @@ -237,12 +237,12 @@ func (r *RpmOstreeClient) Rebase(imgURL, osImageContentDir string) (changed bool // Commit label takes priority if ostreeCsum != "" { if ostreeVersion != "" { - glog.Infof("Pivoting to: %s (%s)", ostreeVersion, ostreeCsum) + klog.Infof("Pivoting to: %s (%s)", ostreeVersion, ostreeCsum) } else { - glog.Infof("Pivoting to: %s", ostreeCsum) + klog.Infof("Pivoting to: %s", ostreeCsum) } } else { - glog.Infof("No com.coreos.ostree-commit label found in metadata! Inspecting...") + klog.Infof("No com.coreos.ostree-commit label found in metadata! Inspecting...") var refText []byte refText, err = runGetOut("ostree", "refs", "--repo", repo) if err != nil { @@ -250,7 +250,7 @@ func (r *RpmOstreeClient) Rebase(imgURL, osImageContentDir string) (changed bool } refs := strings.Split(strings.TrimSpace(string(refText)), "\n") if len(refs) == 1 { - glog.Infof("Using ref %s", refs[0]) + klog.Infof("Using ref %s", refs[0]) var ostreeCsumBytes []byte ostreeCsumBytes, err = runGetOut("ostree", "rev-parse", "--repo", repo, refs[0]) if err != nil { @@ -269,7 +269,7 @@ func (r *RpmOstreeClient) Rebase(imgURL, osImageContentDir string) (changed bool // This will be what will be displayed in `rpm-ostree status` as the "origin spec" customURL := fmt.Sprintf("pivot://%s", imgURL) - glog.Infof("Executing rebase from repo path %s with customImageURL %s and checksum %s", repo, customURL, ostreeCsum) + klog.Infof("Executing rebase from repo path %s with customImageURL %s and checksum %s", repo, customURL, ostreeCsum) args := []string{"rebase", "--experimental", fmt.Sprintf("%s:%s", repo, ostreeCsum), "--custom-origin-url", customURL, "--custom-origin-description", "Managed by machine-config-operator"} @@ -339,7 +339,7 @@ func RpmOstreeIsNewEnoughForLayering() (bool, error) { // RebaseLayered rebases system or errors if already rebased func (r *RpmOstreeClient) RebaseLayered(imgURL string) (err error) { - glog.Infof("Executing rebase to %s", imgURL) + klog.Infof("Executing rebase to %s", imgURL) return runRpmOstree("rebase", "--experimental", "ostree-unverified-registry:"+imgURL) } @@ -379,7 +379,7 @@ func truncate(input string, limit int) string { // runGetOut executes a command, logging it, and return the stdout output. func runGetOut(command string, args ...string) ([]byte, error) { - glog.Infof("Running captured: %s %s", command, strings.Join(args, " ")) + klog.Infof("Running captured: %s %s", command, strings.Join(args, " ")) cmd := exec.Command(command, args...) rawOut, err := cmd.Output() if err != nil { diff --git a/pkg/daemon/update.go b/pkg/daemon/update.go index b3b4c1ec2d..78db8b66ce 100644 --- a/pkg/daemon/update.go +++ b/pkg/daemon/update.go @@ -18,12 +18,12 @@ import ( "github.com/clarketm/json" ign3types "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/golang/glog" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" kubeErrs "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/uuid" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -179,7 +179,7 @@ func (dn *Daemon) compareMachineConfig(oldConfig, newConfig *mcfgv1.MachineConfi return true, fmt.Errorf("error creating machineConfigDiff for comparison: %w", err) } if mcDiff.isEmpty() { - glog.Infof("No changes from %s to %s", oldConfigName, newConfigName) + klog.Infof("No changes from %s to %s", oldConfigName, newConfigName) return false, nil } return true, nil @@ -285,7 +285,7 @@ func ExtractOSImage(imgURL string) (osImageContentDir string, err error) { if _, err = pivotutils.RunExtBackground(cmdRetriesCount, "oc", args...); err != nil { // Workaround fixes for the environment where oc image extract fails. // See https://bugzilla.redhat.com/show_bug.cgi?id=1862979 - glog.Infof("Falling back to using podman cp to fetch OS image content") + klog.Infof("Falling back to using podman cp to fetch OS image content") if err = podmanCopy(imgURL, osImageContentDir); err != nil { return } @@ -317,7 +317,7 @@ func ExtractExtensionsImage(imgURL string) (osExtensionsImageContentDir string, if _, err = pivotutils.RunExtBackground(cmdRetriesCount, "oc", args...); err != nil { // Workaround fixes for the environment where oc image extract fails. // See https://bugzilla.redhat.com/show_bug.cgi?id=1862979 - glog.Infof("Falling back to using podman cp to fetch OS image content") + klog.Infof("Falling back to using podman cp to fetch OS image content") if err = podmanCopy(imgURL, osExtensionsImageContentDir); err != nil { return } @@ -406,7 +406,7 @@ func (dn *CoreOSDaemon) applyOSChanges(mcDiff machineConfigDiff, oldConfig, newC // its ok to create a unique event for this low volume event if _, err := dn.kubeClient.CoreV1().Events(metav1.NamespaceDefault).Create(context.TODO(), event, metav1.CreateOptions{}); err != nil { - glog.Errorf("Failed to create event with reason 'OSUpdateStaged': %v", err) + klog.Errorf("Failed to create event with reason 'OSUpdateStaged': %v", err) } } } @@ -447,7 +447,7 @@ func calculatePostConfigChangeAction(diff *machineConfigDiff, diffFileSet []stri if err := os.Remove(constants.MachineConfigDaemonForceFile); err != nil { return []string{}, fmt.Errorf("failed to remove force validation file: %w", err) } - glog.Infof("Setting post config change action to postConfigChangeActionReboot; %s present", constants.MachineConfigDaemonForceFile) + klog.Infof("Setting post config change action to postConfigChangeActionReboot; %s present", constants.MachineConfigDaemonForceFile) return []string{postConfigChangeActionReboot}, nil } @@ -497,7 +497,7 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi return fmt.Errorf("parsing new Ignition config failed: %w", err) } - glog.Infof("Checking Reconcilable for config %v to %v", oldConfigName, newConfigName) + klog.Infof("Checking Reconcilable for config %v to %v", oldConfigName, newConfigName) // make sure we can actually reconcile this state diff, reconcilableError := reconcilable(oldConfig, newConfig) @@ -528,7 +528,7 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi return err } } else { - glog.Info("Changes do not require drain, skipping.") + klog.Info("Changes do not require drain, skipping.") } // update files on disk that need updating @@ -546,13 +546,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi } }() - if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users); err != nil { return err } defer func() { if retErr != nil { - if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(oldIgnConfig.Passwd.Users); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error rolling back SSH keys updates: %w", errs) return @@ -561,13 +561,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi }() // Set password hash - if err := dn.SetPasswordHash(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { + if err := dn.SetPasswordHash(newIgnConfig.Passwd.Users); err != nil { return err } defer func() { if retErr != nil { - if err := dn.SetPasswordHash(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { + if err := dn.SetPasswordHash(oldIgnConfig.Passwd.Users); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error rolling back password hash updates: %w", errs) return @@ -591,7 +591,7 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi } }() } else { - glog.Info("updating the OS on non-CoreOS nodes is not supported") + klog.Info("updating the OS on non-CoreOS nodes is not supported") } // Ideally we would want to update kernelArguments only via MachineConfigs. @@ -651,13 +651,13 @@ func (dn *Daemon) updateHypershift(oldConfig, newConfig *mcfgv1.MachineConfig, d } }() - if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users); err != nil { return err } defer func() { if retErr != nil { - if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil { + if err := dn.updateSSHKeys(oldIgnConfig.Passwd.Users); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error rolling back SSH keys updates: %w", errs) return @@ -681,14 +681,14 @@ func (dn *Daemon) updateHypershift(oldConfig, newConfig *mcfgv1.MachineConfig, d } }() } else { - glog.Info("updating the OS on non-CoreOS nodes is not supported") + klog.Info("updating the OS on non-CoreOS nodes is not supported") } if err := UpdateTuningArgs(KernelTuningFile, CmdLineFile); err != nil { return err } - glog.Info("Successfully completed Hypershift config update") + klog.Info("Successfully completed Hypershift config update") return nil } @@ -823,6 +823,9 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition Passwd Groups section contains changes") } if !reflect.DeepEqual(oldIgn.Passwd.Users, newIgn.Passwd.Users) { + if len(oldIgn.Passwd.Users) > 0 && len(newIgn.Passwd.Users) == 0 { + return nil, fmt.Errorf("ignition passwd user section contains unsupported changes: user core may not be deleted") + } // there is an update to Users, we must verify that it is ONLY making an acceptable // change to the SSHAuthorizedKeys for the user "core" for _, user := range newIgn.Passwd.Users { @@ -830,12 +833,10 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif return nil, fmt.Errorf("ignition passwd user section contains unsupported changes: non-core user") } } - // We don't want to panic if the "new" users is empty, and it's still reconcilable because the absence of a user here does not mean "remove the user from the system" - if len(newIgn.Passwd.Users) != 0 { - glog.Infof("user data to be verified before ssh update: %v", newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]) - if err := verifyUserFields(newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]); err != nil { - return nil, err - } + + klog.Infof("user data to be verified before ssh update: %v", newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]) + if err := verifyUserFields(newIgn.Passwd.Users[len(newIgn.Passwd.Users)-1]); err != nil { + return nil, err } } } @@ -888,7 +889,7 @@ func reconcilable(oldConfig, newConfig *mcfgv1.MachineConfig) (*machineConfigDif } // we made it through all the checks. reconcile away! - glog.V(2).Info("Configs are reconcilable") + klog.V(2).Info("Configs are reconcilable") mcDiff, err := newMachineConfigDiff(oldConfig, newConfig) if err != nil { return nil, fmt.Errorf("error creating machineConfigDiff: %w", err) @@ -911,7 +912,7 @@ func verifyUserFields(pwdUser ign3types.PasswdUser) error { if !reflect.DeepEqual(emptyUser, tempUser) { return fmt.Errorf("SSH keys and password hash are not reconcilable") } - glog.Info("SSH Keys reconcilable") + klog.Info("SSH Keys reconcilable") } else { return fmt.Errorf("ignition passwd user section contains unsupported changes: user must be core and have 1 or more sshKeys") } @@ -930,7 +931,7 @@ func checkFIPS(current, desired *mcfgv1.MachineConfig) error { if err != nil { if os.IsNotExist(err) { // we just exit cleanly if we're not even on linux - glog.Infof("no %s on this system, skipping FIPS check", fipsFile) + klog.Infof("no %s on this system, skipping FIPS check", fipsFile) return nil } return fmt.Errorf("error reading FIPS file at %s: %s: %w", fipsFile, string(content), err) @@ -941,7 +942,7 @@ func checkFIPS(current, desired *mcfgv1.MachineConfig) error { } if desired.Spec.FIPS == nodeFIPS { if desired.Spec.FIPS { - glog.Infof("FIPS is configured and enabled") + klog.Infof("FIPS is configured and enabled") } // Check if FIPS on the system is at the desired setting current.Spec.FIPS = nodeFIPS @@ -1143,7 +1144,7 @@ func (dn *CoreOSDaemon) applyExtensions(oldConfig, newConfig *mcfgv1.MachineConf } args := dn.generateExtensionsArgs(oldConfig, newConfig) - glog.Infof("Applying extensions : %+q", args) + klog.Infof("Applying extensions : %+q", args) return runRpmOstree(args...) } @@ -1152,7 +1153,7 @@ func (dn *CoreOSDaemon) applyExtensions(oldConfig, newConfig *mcfgv1.MachineConf func (dn *CoreOSDaemon) switchKernel(oldConfig, newConfig *mcfgv1.MachineConfig) error { // We support Kernel update only on RHCOS and SCOS nodes if !dn.os.IsEL() { - glog.Info("updating kernel on non-RHCOS nodes is not supported") + klog.Info("updating kernel on non-RHCOS nodes is not supported") return nil } @@ -1209,7 +1210,7 @@ func (dn *CoreOSDaemon) switchKernel(oldConfig, newConfig *mcfgv1.MachineConfig) // required. in particular, a daemon-reload and restart for any unit files // touched. func (dn *Daemon) updateFiles(oldIgnConfig, newIgnConfig ign3types.Config, skipCertificateWrite bool) error { - glog.Info("Updating files") + klog.Info("Updating files") if err := dn.writeFiles(newIgnConfig.Storage.Files, skipCertificateWrite); err != nil { return err } @@ -1275,7 +1276,7 @@ func (dn *Daemon) isPathInDropins(path string, systemd *ign3types.Systemd) bool // //nolint:gocyclo func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig ign3types.Config) error { - glog.Info("Deleting stale data") + klog.Info("Deleting stale data") newFileSet := make(map[string]struct{}) for _, f := range newIgnConfig.Storage.Files { newFileSet[f.Path] = struct{}{} @@ -1289,7 +1290,7 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig ign3types.Config) e if delErr := os.Remove(noOrigFileStampName(f.Path)); delErr != nil { return fmt.Errorf("deleting noorig file stamp %q: %w", noOrigFileStampName(f.Path), delErr) } - glog.V(2).Infof("Removing file %q completely", f.Path) + klog.V(2).Infof("Removing file %q completely", f.Path) } else if _, err := os.Stat(origFileName(f.Path)); err == nil { // Add a check for backwards compatibility: basically if the file doesn't exist in /usr/etc (on FCOS/RHCOS) // and no rpm is claiming it, we assume that the orig file came from a wrongful backup of a MachineConfig @@ -1314,7 +1315,7 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig ign3types.Config) e if err := restorePath(f.Path); err != nil { return err } - glog.V(2).Infof("Restored file %q", f.Path) + klog.V(2).Infof("Restored file %q", f.Path) continue } @@ -1325,20 +1326,20 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig ign3types.Config) e // Check Systemd.Units.Dropins - don't remove the file if configuration has been converted into a dropin if dn.isPathInDropins(f.Path, &newIgnConfig.Systemd) { - glog.Infof("Not removing file %q: replaced with systemd dropin", f.Path) + klog.Infof("Not removing file %q: replaced with systemd dropin", f.Path) continue } - glog.V(2).Infof("Deleting stale config file: %s", f.Path) + klog.V(2).Infof("Deleting stale config file: %s", f.Path) if err := os.Remove(f.Path); err != nil { newErr := fmt.Errorf("unable to delete %s: %w", f.Path, err) if !os.IsNotExist(err) { return newErr } // otherwise, just warn - glog.Warningf("%v", newErr) + klog.Warningf("%v", newErr) } - glog.Infof("Removed stale file %q", f.Path) + klog.Infof("Removed stale file %q", f.Path) } newUnitSet := make(map[string]struct{}) @@ -1360,24 +1361,24 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig ign3types.Config) e if delErr := os.Remove(noOrigFileStampName(path)); delErr != nil { return fmt.Errorf("deleting noorig file stamp %q: %w", noOrigFileStampName(path), delErr) } - glog.V(2).Infof("Removing file %q completely", path) + klog.V(2).Infof("Removing file %q completely", path) } else if _, err := os.Stat(origFileName(path)); err == nil { if err := restorePath(path); err != nil { return err } - glog.V(2).Infof("Restored file %q", path) + klog.V(2).Infof("Restored file %q", path) continue } - glog.V(2).Infof("Deleting stale systemd dropin file: %s", path) + klog.V(2).Infof("Deleting stale systemd dropin file: %s", path) if err := os.Remove(path); err != nil { newErr := fmt.Errorf("unable to delete %s: %w", path, err) if !os.IsNotExist(err) { return newErr } // otherwise, just warn - glog.Warningf("%v", newErr) + klog.Warningf("%v", newErr) } - glog.Infof("Removed stale systemd dropin %q", path) + klog.Infof("Removed stale systemd dropin %q", path) } } path := filepath.Join(pathSystemd, u.Name) @@ -1387,30 +1388,30 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig ign3types.Config) e // if the system has the service disabled // writeUnits() will catch units that still have references in other MCs if err := dn.presetUnit(u); err != nil { - glog.Infof("Did not restore preset for %s (may not exist): %s", u.Name, err) + klog.Infof("Did not restore preset for %s (may not exist): %s", u.Name, err) } if _, err := os.Stat(noOrigFileStampName(path)); err == nil { if delErr := os.Remove(noOrigFileStampName(path)); delErr != nil { return fmt.Errorf("deleting noorig file stamp %q: %w", noOrigFileStampName(path), delErr) } - glog.V(2).Infof("Removing file %q completely", path) + klog.V(2).Infof("Removing file %q completely", path) } else if _, err := os.Stat(origFileName(path)); err == nil { if err := restorePath(path); err != nil { return err } - glog.V(2).Infof("Restored file %q", path) + klog.V(2).Infof("Restored file %q", path) continue } - glog.V(2).Infof("Deleting stale systemd unit file: %s", path) + klog.V(2).Infof("Deleting stale systemd unit file: %s", path) if err := os.Remove(path); err != nil { newErr := fmt.Errorf("unable to delete %s: %w", path, err) if !os.IsNotExist(err) { return newErr } // otherwise, just warn - glog.Warningf("%v", newErr) + klog.Warningf("%v", newErr) } - glog.Infof("Removed stale systemd unit %q", path) + klog.Infof("Removed stale systemd unit %q", path) } } @@ -1457,7 +1458,7 @@ func (dn *Daemon) enableUnits(units []string) error { return fmt.Errorf("error enabling units: %s", stdouterr) } } - glog.Infof("Enabled systemd units: %v", units) + klog.Infof("Enabled systemd units: %v", units) return nil } @@ -1468,7 +1469,7 @@ func (dn *Daemon) disableUnits(units []string) error { if err != nil { return fmt.Errorf("error disabling unit: %s", stdouterr) } - glog.Infof("Disabled systemd units %v", units) + klog.Infof("Disabled systemd units %v", units) return nil } @@ -1479,7 +1480,7 @@ func (dn *Daemon) presetUnit(unit ign3types.Unit) error { if err != nil { return fmt.Errorf("error running preset on unit: %s", stdouterr) } - glog.Infof("Preset systemd unit %s", unit.Name) + klog.Infof("Preset systemd unit %s", unit.Name) return nil } @@ -1516,7 +1517,7 @@ func (dn *Daemon) writeUnits(units []ign3types.Unit) error { } else { if err := dn.presetUnit(u); err != nil { // Don't fail here, since a unit may have a dropin referencing a nonexisting actual unit - glog.Infof("Could not reset unit preset for %s, skipping. (Error msg: %v)", u.Name, err) + klog.Infof("Could not reset unit preset for %s, skipping. (Error msg: %v)", u.Name, err) } } } @@ -1543,7 +1544,7 @@ func (dn *Daemon) writeFiles(files []ign3types.File, skipCertificateWrite bool) // Ensures that both the SSH root directory (/home/core/.ssh) as well as any // subdirectories are created with the correct (0700) permissions. func createSSHKeyDir(authKeyDir string) error { - glog.Infof("Creating missing SSH key dir at %s", authKeyDir) + klog.Infof("Creating missing SSH key dir at %s", authKeyDir) mkdir := func(dir string) error { return exec.Command("runuser", "-u", constants.CoreUserName, "--", "mkdir", "-m", "0700", "-p", dir).Run() @@ -1576,7 +1577,7 @@ func (dn *Daemon) atomicallyWriteSSHKey(authKeyPath, keys string) error { // Keys should only be written to "/home/core/.ssh" // Once Users are supported fully this should be writing to PasswdUser.HomeDir - glog.Infof("Writing SSH keys to %q", authKeyPath) + klog.Infof("Writing SSH keys to %q", authKeyPath) // Creating CoreUserSSHPath in advance if it doesn't exist in order to ensure it is owned by core user // See https://bugzilla.redhat.com/show_bug.cgi?id=2107113 @@ -1591,36 +1592,23 @@ func (dn *Daemon) atomicallyWriteSSHKey(authKeyPath, keys string) error { return err } - glog.V(2).Infof("Wrote SSH keys to %q", authKeyPath) + klog.V(2).Infof("Wrote SSH keys to %q", authKeyPath) return nil } // Set a given PasswdUser's Password Hash -func (dn *Daemon) SetPasswordHash(newUsers []ign3types.PasswdUser, oldUsers []ign3types.PasswdUser) error { +func (dn *Daemon) SetPasswordHash(newUsers []ign3types.PasswdUser) error { // confirm that user exits - glog.Info("checking if absent users need to be disconfigured") - - // Print and log the oldUsers - fmt.Println("Old Users:") - for _, user := range oldUsers { - fmt.Printf("Name: %s\n", user.Name) - } - - // Print and log the newUsers - fmt.Println("New Users:") - for _, user := range newUsers { - fmt.Printf("Name: %s\n", user.Name) + if len(newUsers) == 0 { + return nil } - // checking if old users need to be deconfigured - deconfigureAbsentUsers(oldUsers, newUsers) - var uErr user.UnknownUserError switch _, err := user.Lookup(constants.CoreUserName); { case err == nil: case errors.As(err, &uErr): - glog.Info("core user does not exist, and creating users is not supported, so ignoring configuration specified for core user") + klog.Info("core user does not exist, and creating users is not supported, so ignoring configuration specified for core user") return nil default: return fmt.Errorf("failed to check if user core exists: %w", err) @@ -1636,7 +1624,7 @@ func (dn *Daemon) SetPasswordHash(newUsers []ign3types.PasswdUser, oldUsers []ig if out, err := exec.Command("usermod", "-p", pwhash, u.Name).CombinedOutput(); err != nil { return fmt.Errorf("Failed to change password for %s: %s:%w", u.Name, out, err) } - glog.Info("Password has been configured") + klog.Info("Password has been configured") } return nil @@ -1650,17 +1638,16 @@ func (dn *Daemon) useNewSSHKeyPath() bool { } // Update a given PasswdUser's SSHKey -func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser, oldUsers []ign3types.PasswdUser) error { - glog.Info("updating SSH keys") - - // Checking to see if absent users need to be deconfigured - deconfigureAbsentUsers(newUsers, oldUsers) +func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser) error { + if len(newUsers) == 0 { + return nil + } var uErr user.UnknownUserError switch _, err := user.Lookup(constants.CoreUserName); { case err == nil: case errors.As(err, &uErr): - glog.Info("core user does not exist, and creating users is not supported, so ignoring configuration specified for core user") + klog.Info("core user does not exist, and creating users is not supported, so ignoring configuration specified for core user") return nil default: return fmt.Errorf("failed to check if user core exists: %w", err) @@ -1703,41 +1690,6 @@ func (dn *Daemon) updateSSHKeys(newUsers []ign3types.PasswdUser, oldUsers []ign3 return nil } -func deconfigureAbsentUsers(oldUsers []ign3types.PasswdUser, newUsers []ign3types.PasswdUser) { - glog.Info("checking to deconfigure the absent user") - for _, oldUser := range oldUsers { - if !isUserPresent(oldUser, newUsers) { - glog.Infof("deconfiguring the user %s\n", oldUser.Name) - deconfigureUser(oldUser) - } - } -} - -func isUserPresent(user ign3types.PasswdUser, userList []ign3types.PasswdUser) bool { - glog.Info("checking if user is present") - for _, u := range userList { - if u.Name == user.Name { - return true - } - } - return false -} - -func deconfigureUser(user ign3types.PasswdUser) error { - glog.Info("deconfiguring the absent user") - - // clear out password and sshkey - pwhash := "" - user.PasswordHash = &pwhash - - if out, err := exec.Command("usermod", "-p", *user.PasswordHash, user.Name).CombinedOutput(); err != nil { - return fmt.Errorf("Failed to change password for %s: %s:%w", user.Name, out, err) - } - - glog.Info("Password and SSH Key have been reset") - return nil -} - // Determines if a file exists by checking for the presence or lack thereof of // an error when stat'ing the file. Returns any other error. func fileExists(path string) (bool, error) { @@ -1803,7 +1755,7 @@ func removeNonIgnitionKeyPathFragments() error { // updateOS updates the system OS to the one specified in newConfig func (dn *Daemon) updateOS(config *mcfgv1.MachineConfig, osImageContentDir string) error { newURL := config.Spec.OSImageURL - glog.Infof("Updating OS to %s", newURL) + klog.Infof("Updating OS to %s", newURL) if _, err := dn.NodeUpdaterClient.Rebase(newURL, osImageContentDir); err != nil { return fmt.Errorf("failed to update OS to %s : %w", newURL, err) } @@ -1841,7 +1793,7 @@ func (dn *Daemon) InplaceUpdateViaNewContainer(target string) error { return err } } else { - glog.Info("SELinux is not enforcing") + klog.Info("SELinux is not enforcing") } systemdPodmanArgs := []string{"--unit", "machine-config-daemon-update-rpmostree-via-container", "-p", "EnvironmentFile=-/etc/mco/proxy.env", "--collect", "--wait", "--", "podman"} @@ -1908,9 +1860,9 @@ func (dn *Daemon) queueRevertRTKernel() error { return err } } else if len(kernelOverrides) > 0 || len(kernelRtLayers) > 0 { - glog.Infof("notice: detected %d overrides and %d kernel-rt layers", len(kernelOverrides), len(kernelRtLayers)) + klog.Infof("notice: detected %d overrides and %d kernel-rt layers", len(kernelOverrides), len(kernelRtLayers)) } else { - glog.Infof("No kernel overrides or replacement detected") + klog.Infof("No kernel overrides or replacement detected") } return nil @@ -1919,7 +1871,7 @@ func (dn *Daemon) queueRevertRTKernel() error { // updateLayeredOS updates the system OS to the one specified in newConfig func (dn *Daemon) updateLayeredOS(config *mcfgv1.MachineConfig) error { newURL := config.Spec.OSImageURL - glog.Infof("Updating OS to layered image %s", newURL) + klog.Infof("Updating OS to layered image %s", newURL) newEnough, err := RpmOstreeIsNewEnoughForLayering() if err != nil { @@ -2055,7 +2007,7 @@ PENDING=%d`, pendingStateMessageID, pending.GetName(), dn.bootID, isPending)) // and gathering stderr into a buffer which will be returned in err // in case of error. func runCmdSync(cmdName string, args ...string) error { - glog.Infof("Running: %s %s", cmdName, strings.Join(args, " ")) + klog.Infof("Running: %s %s", cmdName, strings.Join(args, " ")) cmd := exec.Command(cmdName, args...) var stderr bytes.Buffer cmd.Stdout = os.Stdout @@ -2070,7 +2022,7 @@ func runCmdSync(cmdName string, args ...string) error { // Log a message to the systemd journal as well as our stdout func logSystem(format string, a ...interface{}) { message := fmt.Sprintf(format, a...) - glog.Info(message) + klog.Info(message) // Since we're chrooted into the host rootfs with /run mounted, // we can just talk to the journald socket. Doing this as a // subprocess rather than talking to journald in process since @@ -2082,7 +2034,7 @@ func logSystem(format string, a ...interface{}) { logger.Stdin = &log if err := logger.Run(); err != nil { - glog.Errorf("failed to invoke logger: %v", err) + klog.Errorf("failed to invoke logger: %v", err) } } @@ -2092,7 +2044,7 @@ func (dn *Daemon) catchIgnoreSIGTERM() { if dn.updateActive { return } - glog.Info("Adding SIGTERM protection") + klog.Info("Adding SIGTERM protection") dn.updateActive = true } @@ -2100,7 +2052,7 @@ func (dn *Daemon) cancelSIGTERM() { dn.updateActiveLock.Lock() defer dn.updateActiveLock.Unlock() if dn.updateActive { - glog.Info("Removing SIGTERM protection") + klog.Info("Removing SIGTERM protection") dn.updateActive = false } } @@ -2145,7 +2097,7 @@ func (dn *CoreOSDaemon) applyLayeredOSChanges(mcDiff machineConfigDiff, oldConfi // Override the computed diff if the booted state differs from the oldConfig // https://issues.redhat.com/browse/OCPBUGS-2757 if mcDiff.osUpdate && dn.bootedOSImageURL == newConfig.Spec.OSImageURL { - glog.Infof("Already in desired image %s", newConfig.Spec.OSImageURL) + klog.Infof("Already in desired image %s", newConfig.Spec.OSImageURL) mcDiff.osUpdate = false } @@ -2181,7 +2133,7 @@ func (dn *CoreOSDaemon) applyLayeredOSChanges(mcDiff machineConfigDiff, oldConfi // should be sufficient to discard any applied changes. if retErr != nil { // Print out the error now so that if we fail to cleanup -p, we don't lose it. - glog.Infof("Rolling back applied changes to OS due to error: %v", retErr) + klog.Infof("Rolling back applied changes to OS due to error: %v", retErr) if err := removePendingDeployment(); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error removing staged deployment: %w", errs) @@ -2282,7 +2234,7 @@ func (dn *CoreOSDaemon) applyLegacyOSChanges(mcDiff machineConfigDiff, oldConfig // should be sufficient to discard any applied changes. if retErr != nil { // Print out the error now so that if we fail to cleanup -p, we don't lose it. - glog.Infof("Rolling back applied changes to OS due to error: %v", retErr) + klog.Infof("Rolling back applied changes to OS due to error: %v", retErr) if err := removePendingDeployment(); err != nil { errs := kubeErrs.NewAggregate([]error{err, retErr}) retErr = fmt.Errorf("error removing staged deployment: %w", errs) diff --git a/pkg/daemon/update_test.go b/pkg/daemon/update_test.go index 1af78bbdbd..926ab69a89 100644 --- a/pkg/daemon/update_test.go +++ b/pkg/daemon/update_test.go @@ -409,7 +409,7 @@ func TestReconcilableSSH(t *testing.T) { newIgnCfg.Passwd.Users = nil newMcfg = helpers.CreateMachineConfigFromIgnition(newIgnCfg) _, errMsg = reconcilable(oldMcfg, newMcfg) - checkReconcilableResults(t, "SSH", errMsg) + checkIrreconcilableResults(t, "SSH", errMsg) } func TestWriteFiles(t *testing.T) { @@ -502,9 +502,8 @@ func TestUpdateSSHKeys(t *testing.T) { // Set up machineconfigs that are identical except for SSH keys tempUser := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"1234", "4567"}} newIgnCfg := ctrlcommon.NewIgnConfig() - oldIgnConfig := ctrlcommon.NewIgnConfig() newIgnCfg.Passwd.Users = []ign3types.PasswdUser{tempUser} - err := d.updateSSHKeys(newIgnCfg.Passwd.Users, oldIgnConfig.Passwd.Users) + err := d.updateSSHKeys(newIgnCfg.Passwd.Users) if err != nil { t.Errorf("Expected no error. Got %s.", err) @@ -513,7 +512,7 @@ func TestUpdateSSHKeys(t *testing.T) { // if Users is empty, nothing should happen and no error should ever be generated newIgnCfg2 := ctrlcommon.NewIgnConfig() newIgnCfg2.Passwd.Users = []ign3types.PasswdUser{} - err = d.updateSSHKeys(newIgnCfg2.Passwd.Users, oldIgnConfig.Passwd.Users) + err = d.updateSSHKeys(newIgnCfg2.Passwd.Users) if err != nil { t.Errorf("Expected no error. Got: %s", err) } diff --git a/pkg/daemon/writer.go b/pkg/daemon/writer.go index a7f3d60f02..a5c11d83be 100644 --- a/pkg/daemon/writer.go +++ b/pkg/daemon/writer.go @@ -13,13 +13,13 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "github.com/golang/glog" "github.com/openshift/machine-config-operator/internal" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/daemon/constants" corev1 "k8s.io/api/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1lister "k8s.io/client-go/listers/core/v1" + "k8s.io/klog/v2" ) const ( @@ -90,14 +90,14 @@ func newNodeWriter(nodeName string, stopCh <-chan struct{}) (NodeWriter, error) return &clusterNodeWriter{}, err } - glog.Infof("NodeWriter initialized with credentials from %s", nodeWriterKubeconfigPath) + klog.Infof("NodeWriter initialized with credentials from %s", nodeWriterKubeconfigPath) informer := informers.NewSharedInformerFactory(kubeClient, ctrlcommon.DefaultResyncPeriod()()) nodeInformer := informer.Core().V1().Nodes() nodeLister := nodeInformer.Lister() nodeListerSynced := nodeInformer.Informer().HasSynced eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.V(2).Infof) + eventBroadcaster.StartLogging(klog.V(2).Infof) eventBroadcaster.StartRecordingToSink(&corev1client.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) nw := &clusterNodeWriter{ @@ -124,7 +124,7 @@ func newNodeWriter(nodeName string, stopCh <-chan struct{}) (NodeWriter, error) // return if the stop channel is closed. Intended to be run via a goroutine. func (nw *clusterNodeWriter) Run(stop <-chan struct{}) { if !cache.WaitForCacheSync(stop, nw.nodeListerSynced) { - glog.Fatal("failed to sync initial listers cache") + klog.Fatal("failed to sync initial listers cache") } for { @@ -173,7 +173,7 @@ func (nw *clusterNodeWriter) SetWorking() error { // SetUnreconcilable sets the state to Unreconcilable. func (nw *clusterNodeWriter) SetUnreconcilable(err error) error { - glog.Errorf("Marking Unreconcilable due to: %v", err) + klog.Errorf("Marking Unreconcilable due to: %v", err) // truncatedErr caps error message at a reasonable length to limit the risk of hitting the total // annotation size limit (256 kb) at any point truncatedErr := fmt.Sprintf("%.2000s", err.Error()) @@ -189,7 +189,7 @@ func (nw *clusterNodeWriter) SetUnreconcilable(err error) error { } r := <-respChan if r.err != nil { - glog.Errorf("Error setting Unreconcilable annotation for node %s: %v", nw.nodeName, r.err) + klog.Errorf("Error setting Unreconcilable annotation for node %s: %v", nw.nodeName, r.err) } return r.err } @@ -197,7 +197,7 @@ func (nw *clusterNodeWriter) SetUnreconcilable(err error) error { // SetDegraded logs the error and sets the state to Degraded. // Returns an error if it couldn't set the annotation. func (nw *clusterNodeWriter) SetDegraded(err error) error { - glog.Errorf("Marking Degraded due to: %v", err) + klog.Errorf("Marking Degraded due to: %v", err) // truncatedErr caps error message at a reasonable length to limit the risk of hitting the total // annotation size limit (256 kb) at any point truncatedErr := fmt.Sprintf("%.2000s", err.Error()) @@ -213,7 +213,7 @@ func (nw *clusterNodeWriter) SetDegraded(err error) error { } r := <-respChan if r.err != nil { - glog.Errorf("Error setting Degraded annotation for node %s: %v", nw.nodeName, r.err) + klog.Errorf("Error setting Degraded annotation for node %s: %v", nw.nodeName, r.err) } return r.err } diff --git a/pkg/operator/bootstrap.go b/pkg/operator/bootstrap.go index f4d9fae0fa..7d378c4ed8 100644 --- a/pkg/operator/bootstrap.go +++ b/pkg/operator/bootstrap.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/golang/glog" + "k8s.io/klog/v2" configv1 "github.com/openshift/api/config/v1" configscheme "github.com/openshift/client-go/config/clientset/versioned/scheme" @@ -186,7 +186,7 @@ func RenderBootstrap( var err error switch { case len(m.name) > 0: - glog.Info(m.name) + klog.Info(m.name) b, err = renderAsset(config, m.name) if err != nil { return err @@ -296,7 +296,7 @@ func loadBootstrapCloudProviderConfig(infra *configv1.Infrastructure, cloudConfi } cloudConf, ok := cm.Data["cloud.conf"] if !ok { - glog.Infof("falling back to reading cloud provider config from user specified key %s", infra.Spec.CloudConfig.Key) + klog.Infof("falling back to reading cloud provider config from user specified key %s", infra.Spec.CloudConfig.Key) cloudConf = cm.Data[infra.Spec.CloudConfig.Key] } return cloudConf, nil diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index c66d77c59a..d12d022c7f 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/golang/glog" + "k8s.io/klog/v2" configclientset "github.com/openshift/client-go/config/clientset/versioned" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -141,7 +141,7 @@ func New( maoSecretInformer coreinformersv1.SecretInformer, ) *Operator { eventBroadcaster := record.NewBroadcaster() - eventBroadcaster.StartLogging(glog.Infof) + eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartRecordingToSink(&coreclientsetv1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")}) optr := &Operator{ @@ -234,10 +234,10 @@ func (optr *Operator) Run(workers int, stopCh <-chan struct{}) { _, err := apiClient.CustomResourceDefinitions().Get(context.TODO(), "controllerconfigs.machineconfiguration.openshift.io", metav1.GetOptions{}) if err != nil { if apierrors.IsNotFound(err) { - glog.Infof("Couldn't find controllerconfig CRD, in cluster bringup mode") + klog.Infof("Couldn't find controllerconfig CRD, in cluster bringup mode") optr.inClusterBringup = true } else { - glog.Errorf("While checking for cluster bringup: %v", err) + klog.Errorf("While checking for cluster bringup: %v", err) } } @@ -259,7 +259,7 @@ func (optr *Operator) Run(workers int, stopCh <-chan struct{}) { optr.mcpListerSynced, optr.mcListerSynced, optr.dnsListerSynced) { - glog.Error("failed to sync caches") + klog.Error("failed to sync caches") return } @@ -268,13 +268,13 @@ func (optr *Operator) Run(workers int, stopCh <-chan struct{}) { if !cache.WaitForCacheSync(stopCh, optr.ccListerSynced, ) { - glog.Error("failed to sync caches") + klog.Error("failed to sync caches") return } } - glog.Info("Starting MachineConfigOperator") - defer glog.Info("Shutting down MachineConfigOperator") + klog.Info("Starting MachineConfigOperator") + defer klog.Info("Shutting down MachineConfigOperator") optr.stopCh = stopCh @@ -334,22 +334,22 @@ func (optr *Operator) handleErr(err error, key interface{}) { } if optr.queue.NumRequeues(key) < maxRetries { - glog.V(2).Infof("Error syncing operator %v: %v", key, err) + klog.V(2).Infof("Error syncing operator %v: %v", key, err) optr.queue.AddRateLimited(key) return } utilruntime.HandleError(err) - glog.V(2).Infof("Dropping operator %q out of the queue: %v", key, err) + klog.V(2).Infof("Dropping operator %q out of the queue: %v", key, err) optr.queue.Forget(key) optr.queue.AddAfter(key, 1*time.Minute) } func (optr *Operator) sync(key string) error { startTime := time.Now() - glog.V(4).Infof("Started syncing operator %q (%v)", key, startTime) + klog.V(4).Infof("Started syncing operator %q (%v)", key, startTime) defer func() { - glog.V(4).Infof("Finished syncing operator %q (%v)", key, time.Since(startTime)) + klog.V(4).Infof("Finished syncing operator %q (%v)", key, time.Since(startTime)) }() // syncFuncs is the list of sync functions that are executed in order. diff --git a/pkg/operator/render.go b/pkg/operator/render.go index 2950587ea6..19303b0592 100644 --- a/pkg/operator/render.go +++ b/pkg/operator/render.go @@ -10,7 +10,7 @@ import ( "github.com/apparentlymart/go-cidr/cidr" "github.com/ghodss/yaml" - "github.com/golang/glog" + "k8s.io/klog/v2" configv1 "github.com/openshift/api/config/v1" @@ -175,7 +175,7 @@ func createDiscoveredControllerConfigSpec(infra *configv1.Infrastructure, networ if proxy != nil { if proxy.Status == (configv1.ProxyStatus{}) { - glog.V(2).Info("Not setting proxy config because Proxy status is empty") + klog.V(2).Info("Not setting proxy config because Proxy status is empty") } else { ccSpec.Proxy = &proxy.Status } diff --git a/pkg/operator/status.go b/pkg/operator/status.go index 3b8e20f1f8..89d5866db9 100644 --- a/pkg/operator/status.go +++ b/pkg/operator/status.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/golang/glog" configv1 "github.com/openshift/api/config/v1" cov1helpers "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers" corev1 "k8s.io/api/core/v1" @@ -17,6 +16,7 @@ import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" @@ -325,7 +325,7 @@ func (optr *Operator) syncUpgradeableStatus() error { if !updating && !degraded { skewStatus, status, err := optr.isKubeletSkewSupported(pools) if err != nil { - glog.Errorf("Error checking version skew: %v, kubelet skew status: %v, status reason: %v, status message: %v", err, skewStatus, status.Reason, status.Message) + klog.Errorf("Error checking version skew: %v, kubelet skew status: %v, status reason: %v, status message: %v", err, skewStatus, status.Reason, status.Message) coStatus.Reason = status.Reason coStatus.Message = status.Message return optr.updateStatus(co, coStatus) @@ -344,13 +344,13 @@ func (optr *Operator) syncUpgradeableStatus() error { Namespace: co.Namespace, UID: co.GetUID(), } - glog.Infof("kubelet skew status: %v, status reason: %v", skewStatus, status.Reason) + klog.Infof("kubelet skew status: %v, status reason: %v", skewStatus, status.Reason) optr.eventRecorder.Eventf(mcoObjectRef, corev1.EventTypeWarning, coStatus.Reason, coStatus.Message) return optr.updateStatus(co, coStatus) case skewPresent: coStatus.Reason = status.Reason coStatus.Message = status.Message - glog.Infof("kubelet skew status: %v, status reason: %v", skewStatus, status.Reason) + klog.Infof("kubelet skew status: %v, status reason: %v", skewStatus, status.Reason) return optr.updateStatus(co, coStatus) } } @@ -373,7 +373,7 @@ func (optr *Operator) syncMetrics() error { latestTime = cond.LastTransitionTime } } - glog.Infof("Condition: %s, Machines: %d, UpdatedMachines: %d, DegradedMachines: %d, UnavailableMachines: %d", string(cond.Type), pool.Status.MachineCount, pool.Status.UpdatedMachineCount, pool.Status.DegradedMachineCount, pool.Status.UnavailableMachineCount) + klog.Infof("Condition: %s, Machines: %d, UpdatedMachines: %d, DegradedMachines: %d, UnavailableMachines: %d", string(cond.Type), pool.Status.MachineCount, pool.Status.UpdatedMachineCount, pool.Status.DegradedMachineCount, pool.Status.UnavailableMachineCount) mcoState.WithLabelValues(pool.Name, string(cond.Type), cond.Reason).SetToCurrentTime() mcoMachineCount.WithLabelValues(pool.Name).Set(float64(pool.Status.MachineCount)) mcoUpdatedMachineCount.WithLabelValues(pool.Name).Set(float64(pool.Status.UpdatedMachineCount)) @@ -566,7 +566,7 @@ func (optr *Operator) initializeClusterOperator() (*configv1.ClusterOperator, er func (optr *Operator) setOperatorStatusExtension(status *configv1.ClusterOperatorStatus, statusErr error) { statuses, err := optr.allMachineConfigPoolStatus() if err != nil { - glog.Error(err) + klog.Error(err) return } if statusErr != nil { @@ -574,7 +574,7 @@ func (optr *Operator) setOperatorStatusExtension(status *configv1.ClusterOperato } raw, err := json.Marshal(statuses) if err != nil { - glog.Error(err) + klog.Error(err) return } status.Extension.Raw = raw diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index be1e14a95a..86612370aa 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -14,7 +14,6 @@ import ( "strings" "time" - "github.com/golang/glog" configclientscheme "github.com/openshift/client-go/config/clientset/versioned/scheme" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -28,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/cache" + "k8s.io/klog/v2" configv1 "github.com/openshift/api/config/v1" "github.com/openshift/library-go/pkg/operator/resource/resourceapply" @@ -127,7 +127,7 @@ func (optr *Operator) syncAll(syncFuncs []syncFunc) error { err: sf.fn(optr.renderConfig), } if optr.inClusterBringup { - glog.Infof("[init mode] synced %s in %v", sf.name, time.Since(startTime)) + klog.Infof("[init mode] synced %s in %v", sf.name, time.Since(startTime)) } if syncErr.err != nil { // Keep rendering controllerconfig if the daemon sync fails so (among other things) @@ -137,7 +137,7 @@ func (optr *Operator) syncAll(syncFuncs []syncFunc) error { if err := optr.safetySyncControllerConfig(optr.renderConfig); err != nil { // we don't want this error to supersede the actual error // it's just "oh also, we tried to save you, but that didn't work either" - glog.Errorf("Error performing safety controllerconfig sync: %v", err) + klog.Errorf("Error performing safety controllerconfig sync: %v", err) } } break @@ -172,7 +172,7 @@ func (optr *Operator) syncAll(syncFuncs []syncFunc) error { } if optr.inClusterBringup && syncErr.err == nil { - glog.Infof("Initialization complete") + klog.Infof("Initialization complete") optr.inClusterBringup = false } @@ -232,12 +232,12 @@ func (optr *Operator) syncRenderConfig(_ *renderConfig) error { } if optr.inClusterBringup { - glog.V(4).Info("Starting inClusterBringup informers cache sync") + klog.V(4).Info("Starting inClusterBringup informers cache sync") // sync now our own informers after having installed the CRDs if !cache.WaitForCacheSync(optr.stopCh, optr.ccListerSynced) { return fmt.Errorf("failed to sync caches for informers") } - glog.V(4).Info("Finished inClusterBringup informers cache sync") + klog.V(4).Info("Finished inClusterBringup informers cache sync") } // sync up the images used by operands. @@ -593,7 +593,7 @@ func (optr *Operator) applyManifests(config *renderConfig, paths manifestPaths) // we need to keep syncing controllerconfig, but something (like daemon sync failing) is preventing // us from getting to the actual controller sync func (optr *Operator) safetySyncControllerConfig(config *renderConfig) error { - glog.Infof("Performing safety controllerconfig sync") + klog.Infof("Performing safety controllerconfig sync") // If we have an existing controllerconfig, we might be able to keep rendering existingCc, err := optr.ccLister.Get(ctrlcommon.ControllerConfigName) @@ -680,9 +680,9 @@ func (optr *Operator) syncMachineConfigController(config *renderConfig) error { } func (optr *Operator) syncMachineOSBuilder(config *renderConfig) error { - glog.V(4).Info("Machine OS Builder sync started") + klog.V(4).Info("Machine OS Builder sync started") defer func() { - glog.V(4).Info("Machine OS Builder sync complete") + klog.V(4).Info("Machine OS Builder sync complete") }() paths := manifestPaths{ @@ -736,7 +736,7 @@ func (optr *Operator) reconcileMachineOSBuilder(mob *appsv1.Deployment) error { // If the deployment does not exist and we do not have any opted-in pools, we // should create the deployment with zero replicas so that it exists. if apierrors.IsNotFound(err) && len(layeredMCPs) == 0 { - glog.Infof("Created Machine OS Builder deployment") + klog.Infof("Created Machine OS Builder deployment") return optr.updateMachineOSBuilderDeployment(mob, 0) } @@ -747,14 +747,14 @@ func (optr *Operator) reconcileMachineOSBuilder(mob *appsv1.Deployment) error { for _, mcp := range layeredMCPs { layeredMCPNames = append(layeredMCPNames, mcp.Name) } - glog.Infof("Starting Machine OS Builder pod because MachineConfigPool(s) opted into layering: %v", layeredMCPNames) + klog.Infof("Starting Machine OS Builder pod because MachineConfigPool(s) opted into layering: %v", layeredMCPNames) return optr.updateMachineOSBuilderDeployment(mob, 1) } // If we do not have opted-in pools and the Machine OS Builder deployment is // running, scale it down. if len(layeredMCPs) == 0 && isRunning { - glog.Infof("Shutting down Machine OS Builder pod because no MachineConfigPool(s) opted into layering") + klog.Infof("Shutting down Machine OS Builder pod because no MachineConfigPool(s) opted into layering") return optr.updateMachineOSBuilderDeployment(mob, 0) } @@ -809,8 +809,7 @@ func (optr *Operator) getLayeredMachineConfigPools() ([]*mcfgv1.MachineConfigPoo // TODO: Once https://github.com/openshift/machine-config-operator/pull/3731 // lands, change this to consume ctrlcommon.LayeringEnabledPoolLabel instead // of having this hard-coded here. - layeringEnabledPoolLabel := "machineconfiguration.openshift.io/layering-enabled" - requirement, err := labels.NewRequirement(layeringEnabledPoolLabel, selection.Exists, []string{}) + requirement, err := labels.NewRequirement(ctrlcommon.LayeringEnabledPoolLabel, selection.Exists, []string{}) if err != nil { return []*mcfgv1.MachineConfigPool{}, err } @@ -900,7 +899,7 @@ func (optr *Operator) syncRequiredMachineConfigPools(_ *renderConfig) error { return false, nil } if co == nil { - glog.Warning("no clusteroperator for machine-config") + klog.Warning("no clusteroperator for machine-config") return false, nil } optr.setOperatorStatusExtension(&co.Status, lastErr) @@ -921,10 +920,10 @@ func (optr *Operator) syncRequiredMachineConfigPools(_ *renderConfig) error { degraded := isPoolStatusConditionTrue(pool, mcfgv1.MachineConfigPoolDegraded) if degraded { lastErr = fmt.Errorf("error pool %s is not ready, retrying. Status: (pool degraded: %v total: %d, ready %d, updated: %d, unavailable: %d)", pool.Name, degraded, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount) - glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) + klog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) syncerr := optr.syncUpgradeableStatus() if syncerr != nil { - glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) + klog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) } return false, nil } @@ -934,7 +933,7 @@ func (optr *Operator) syncRequiredMachineConfigPools(_ *renderConfig) error { if hasRequiredPoolLabel { newFormatOpURL, _, opURL, err := optr.getOsImageURLs(optr.namespace) if err != nil { - glog.Errorf("Error getting configmap osImageURL: %q", err) + klog.Errorf("Error getting configmap osImageURL: %q", err) return false, nil } releaseVersion, _ := optr.vStore.Get("operator") @@ -949,7 +948,7 @@ func (optr *Operator) syncRequiredMachineConfigPools(_ *renderConfig) error { lastErr = fmt.Errorf("pool %s has not progressed to latest configuration: %w, retrying", pool.Name, err) syncerr := optr.syncUpgradeableStatus() if syncerr != nil { - glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) + klog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) } return false, nil } @@ -961,7 +960,7 @@ func (optr *Operator) syncRequiredMachineConfigPools(_ *renderConfig) error { lastErr = fmt.Errorf("error required pool %s is not ready, retrying. Status: (total: %d, ready %d, updated: %d, unavailable: %d, degraded: %d)", pool.Name, pool.Status.MachineCount, pool.Status.ReadyMachineCount, pool.Status.UpdatedMachineCount, pool.Status.UnavailableMachineCount, pool.Status.DegradedMachineCount) syncerr := optr.syncUpgradeableStatus() if syncerr != nil { - glog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) + klog.Errorf("Error syncingUpgradeableStatus: %q", syncerr) } // If we don't account for pause here, we will spin in this loop until we hit the 10 minute timeout because paused pools can't sync. if pool.Spec.Paused { @@ -972,8 +971,8 @@ func (optr *Operator) syncRequiredMachineConfigPools(_ *renderConfig) error { } return true, nil }); err != nil { - if err == wait.ErrWaitTimeout { - glog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) + if wait.Interrupted(err) { + klog.Errorf("Error syncing Required MachineConfigPools: %q", lastErr) errs := kubeErrs.NewAggregate([]error{err, lastErr}) return fmt.Errorf("error during syncRequiredMachineConfigPools: %w", errs) } @@ -1255,7 +1254,7 @@ func mergeCertWithCABundle(initialBundle, newBundle []byte, subject string) []by } c, err := x509.ParseCertificate(b.Bytes) if err != nil { - glog.Warningf("Could not parse initial bundle certificate: %v", err) + klog.Warningf("Could not parse initial bundle certificate: %v", err) continue } if strings.Contains(c.Subject.String(), subject) { diff --git a/pkg/server/api.go b/pkg/server/api.go index eb98b6ae73..646d753731 100644 --- a/pkg/server/api.go +++ b/pkg/server/api.go @@ -11,8 +11,8 @@ import ( "github.com/clarketm/json" "github.com/coreos/go-semver/semver" - "github.com/golang/glog" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/klog/v2" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" ) @@ -61,15 +61,15 @@ func NewAPIServer(a *APIHandler, p int, is bool, c, k string) *APIServer { func (a *APIServer) Serve() { mcs := getHTTPServerCfg(fmt.Sprintf(":%v", a.port), a.handler) - glog.Infof("Launching server on %s", mcs.Addr) + klog.Infof("Launching server on %s", mcs.Addr) if a.insecure { // Serve a non TLS server. if err := mcs.ListenAndServe(); err != http.ErrServerClosed { - glog.Exitf("Machine Config Server exited with error: %v", err) + klog.Exitf("Machine Config Server exited with error: %v", err) } } else { if err := mcs.ListenAndServeTLS(a.cert, a.key); err != http.ErrServerClosed { - glog.Exitf("Machine Config Server exited with error: %v", err) + klog.Exitf("Machine Config Server exited with error: %v", err) } } } @@ -106,13 +106,13 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { poolName := path.Base(r.URL.Path) useragent := r.Header.Get("User-Agent") acceptHeader := r.Header.Get("Accept") - glog.Infof("Pool %s requested by address:%q User-Agent:%q Accept-Header: %q", poolName, r.RemoteAddr, useragent, acceptHeader) + klog.Infof("Pool %s requested by address:%q User-Agent:%q Accept-Header: %q", poolName, r.RemoteAddr, useragent, acceptHeader) reqConfigVer, err := detectSpecVersionFromAcceptHeader(acceptHeader) if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusBadRequest) - glog.Error(err) + klog.Error(err) return } @@ -125,7 +125,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusInternalServerError) - glog.Errorf("couldn't get config for req: %v, error: %v", cr, err) + klog.Errorf("couldn't get config for req: %v, error: %v", cr, err) return } if conf == nil { @@ -141,7 +141,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusInternalServerError) - glog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) + klog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) return } serveConf = &converted34 @@ -151,7 +151,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusInternalServerError) - glog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) + klog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) return } serveConf = &converted33 @@ -162,7 +162,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusInternalServerError) - glog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) + klog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) return } @@ -173,7 +173,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusInternalServerError) - glog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) + klog.Errorf("couldn't convert config for req: %v, error: %v", cr, err) return } @@ -184,7 +184,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { w.Header().Set("Content-Length", "0") w.WriteHeader(http.StatusInternalServerError) - glog.Errorf("failed to marshal %v config: %v", cr, err) + klog.Errorf("failed to marshal %v config: %v", cr, err) return } @@ -197,7 +197,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { _, err = w.Write(data) if err != nil { - glog.Errorf("failed to write %v response: %v", cr, err) + klog.Errorf("failed to write %v response: %v", cr, err) } } diff --git a/pkg/server/bootstrap_server.go b/pkg/server/bootstrap_server.go index 464fdc264c..c8fb0b0bd5 100644 --- a/pkg/server/bootstrap_server.go +++ b/pkg/server/bootstrap_server.go @@ -7,9 +7,9 @@ import ( "path" yaml "github.com/ghodss/yaml" - "github.com/golang/glog" "k8s.io/apimachinery/pkg/runtime" clientcmd "k8s.io/client-go/tools/clientcmd/api/v1" + "k8s.io/klog/v2" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" @@ -62,10 +62,10 @@ func (bsc *bootstrapServer) GetConfig(cr poolRequest) (*runtime.RawExtension, er } // 1. Read the Machine Config Pool object. fileName := path.Join(bsc.serverBaseDir, "machine-pools", cr.machineConfigPool+".yaml") - glog.Infof("reading file %q", fileName) + klog.Infof("reading file %q", fileName) data, err := os.ReadFile(fileName) if os.IsNotExist(err) { - glog.Errorf("could not find file: %s", fileName) + klog.Errorf("could not find file: %s", fileName) return nil, nil } if err != nil { @@ -82,10 +82,10 @@ func (bsc *bootstrapServer) GetConfig(cr poolRequest) (*runtime.RawExtension, er // 2. Read the Machine Config object. fileName = path.Join(bsc.serverBaseDir, "machine-configs", currConf+".yaml") - glog.Infof("reading file %q", fileName) + klog.Infof("reading file %q", fileName) data, err = os.ReadFile(fileName) if os.IsNotExist(err) { - glog.Errorf("could not find file: %s", fileName) + klog.Errorf("could not find file: %s", fileName) return nil, nil } if err != nil { diff --git a/test/e2e/mco_test.go b/test/e2e/mco_test.go index d84da96828..17aed7f715 100644 --- a/test/e2e/mco_test.go +++ b/test/e2e/mco_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/golang/glog" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/pkg/controller/node" e2e_shared_test "github.com/openshift/machine-config-operator/test/e2e-shared-tests" @@ -18,6 +17,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/klog/v2" ) func TestClusterOperatorRelatedObjects(t *testing.T) { @@ -73,7 +73,7 @@ func TestMastersSchedulable(t *testing.T) { func checkMasterNodesSchedulability(cs *framework.ClientSet, masterSchedulable bool) bool { masterNodes, err := cs.CoreV1Interface.Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: "node-role.kubernetes.io/master="}) if err != nil { - glog.Errorf("error while listing master nodes with %v", err) + klog.Errorf("error while listing master nodes with %v", err) } if masterSchedulable { for _, masterNode := range masterNodes.Items { @@ -107,7 +107,7 @@ func CheckMasterIsAlreadySchedulable(master *corev1.Node) bool { func waitForAllMastersUpdate(cs *framework.ClientSet, mastersSchedulable bool) error { return wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) { if !checkMasterNodesSchedulability(cs, mastersSchedulable) { - glog.Infof("All masters are not in desired state") + klog.Infof("All masters are not in desired state") return false, nil } return true, nil diff --git a/test/framework/clientset.go b/test/framework/clientset.go index 761a0e1d2a..06dbb3dfa1 100644 --- a/test/framework/clientset.go +++ b/test/framework/clientset.go @@ -4,7 +4,6 @@ import ( "fmt" "os" - "github.com/golang/glog" clientbuildv1 "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1" clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" clientimagev1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1" @@ -15,6 +14,7 @@ import ( corev1client "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + "k8s.io/klog/v2" ) type ClientSet struct { @@ -47,10 +47,10 @@ func NewClientSet(kubeconfig string) *ClientSet { } if kubeconfig != "" { - glog.V(4).Infof("Loading kube client config from path %q", kubeconfig) + klog.V(4).Infof("Loading kube client config from path %q", kubeconfig) config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) } else { - glog.V(4).Infof("Using in-cluster kube client config") + klog.V(4).Infof("Using in-cluster kube client config") config, err = rest.InClusterConfig() } if err != nil { diff --git a/vendor/github.com/golang/glog/LICENSE b/vendor/github.com/golang/glog/LICENSE deleted file mode 100644 index 37ec93a14f..0000000000 --- a/vendor/github.com/golang/glog/LICENSE +++ /dev/null @@ -1,191 +0,0 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. - -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. - -2. Grant of Copyright License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. - -3. Grant of Patent License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. - -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. - -5. Submission of Contributions. - -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. - -6. Trademarks. - -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. - -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. - -8. Limitation of Liability. - -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. - -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own -identifying information. (Don't include the brackets!) The text should be -enclosed in the appropriate comment syntax for the file format. We also -recommend that a file or class name and description of purpose be included on -the same "printed page" as the copyright notice for easier identification within -third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/golang/glog/README.md b/vendor/github.com/golang/glog/README.md deleted file mode 100644 index a4f73883b2..0000000000 --- a/vendor/github.com/golang/glog/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# glog - -[![PkgGoDev](https://pkg.go.dev/badge/github.com/golang/glog)](https://pkg.go.dev/github.com/golang/glog) - -Leveled execution logs for Go. - -This is an efficient pure Go implementation of leveled logs in the -manner of the open source C++ package [_glog_](https://github.com/google/glog). - -By binding methods to booleans it is possible to use the log package without paying the expense of evaluating the arguments to the log. Through the `-vmodule` flag, the package also provides fine-grained -control over logging at the file level. - -The comment from `glog.go` introduces the ideas: - -Package _glog_ implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides the functions Info, Warning, Error, Fatal, plus formatting variants such as Infof. It also provides V-style loggingcontrolled by the `-v` and `-vmodule=file=2` flags. - -Basic examples: - -```go -glog.Info("Prepare to repel boarders") - -glog.Fatalf("Initialization failed: %s", err) -``` - -See the documentation for the V function for an explanation of these examples: - -```go -if glog.V(2) { - glog.Info("Starting transaction...") -} -glog.V(2).Infoln("Processed", nItems, "elements") -``` - -The repository contains an open source version of the log package used inside Google. The master copy of the source lives inside Google, not here. The code in this repo is for export only and is not itself under development. Feature requests will be ignored. - -Send bug reports to golang-nuts@googlegroups.com. diff --git a/vendor/github.com/golang/glog/glog.go b/vendor/github.com/golang/glog/glog.go deleted file mode 100644 index 718c34f886..0000000000 --- a/vendor/github.com/golang/glog/glog.go +++ /dev/null @@ -1,1180 +0,0 @@ -// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/ -// -// Copyright 2013 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. -// It provides functions Info, Warning, Error, Fatal, plus formatting variants such as -// Infof. It also provides V-style logging controlled by the -v and -vmodule=file=2 flags. -// -// Basic examples: -// -// glog.Info("Prepare to repel boarders") -// -// glog.Fatalf("Initialization failed: %s", err) -// -// See the documentation for the V function for an explanation of these examples: -// -// if glog.V(2) { -// glog.Info("Starting transaction...") -// } -// -// glog.V(2).Infoln("Processed", nItems, "elements") -// -// Log output is buffered and written periodically using Flush. Programs -// should call Flush before exiting to guarantee all log output is written. -// -// By default, all log statements write to files in a temporary directory. -// This package provides several flags that modify this behavior. -// As a result, flag.Parse must be called before any logging is done. -// -// -logtostderr=false -// Logs are written to standard error instead of to files. -// -alsologtostderr=false -// Logs are written to standard error as well as to files. -// -stderrthreshold=ERROR -// Log events at or above this severity are logged to standard -// error as well as to files. -// -log_dir="" -// Log files will be written to this directory instead of the -// default temporary directory. -// -// Other flags provide aids to debugging. -// -// -log_backtrace_at="" -// When set to a file and line number holding a logging statement, -// such as -// -log_backtrace_at=gopherflakes.go:234 -// a stack trace will be written to the Info log whenever execution -// hits that statement. (Unlike with -vmodule, the ".go" must be -// present.) -// -v=0 -// Enable V-leveled logging at the specified level. -// -vmodule="" -// The syntax of the argument is a comma-separated list of pattern=N, -// where pattern is a literal file name (minus the ".go" suffix) or -// "glob" pattern and N is a V level. For instance, -// -vmodule=gopher*=3 -// sets the V level to 3 in all Go files whose names begin "gopher". -// -package glog - -import ( - "bufio" - "bytes" - "errors" - "flag" - "fmt" - "io" - stdLog "log" - "os" - "path/filepath" - "runtime" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" -) - -// severity identifies the sort of log: info, warning etc. It also implements -// the flag.Value interface. The -stderrthreshold flag is of type severity and -// should be modified only through the flag.Value interface. The values match -// the corresponding constants in C++. -type severity int32 // sync/atomic int32 - -// These constants identify the log levels in order of increasing severity. -// A message written to a high-severity log file is also written to each -// lower-severity log file. -const ( - infoLog severity = iota - warningLog - errorLog - fatalLog - numSeverity = 4 -) - -const severityChar = "IWEF" - -var severityName = []string{ - infoLog: "INFO", - warningLog: "WARNING", - errorLog: "ERROR", - fatalLog: "FATAL", -} - -// get returns the value of the severity. -func (s *severity) get() severity { - return severity(atomic.LoadInt32((*int32)(s))) -} - -// set sets the value of the severity. -func (s *severity) set(val severity) { - atomic.StoreInt32((*int32)(s), int32(val)) -} - -// String is part of the flag.Value interface. -func (s *severity) String() string { - return strconv.FormatInt(int64(*s), 10) -} - -// Get is part of the flag.Value interface. -func (s *severity) Get() interface{} { - return *s -} - -// Set is part of the flag.Value interface. -func (s *severity) Set(value string) error { - var threshold severity - // Is it a known name? - if v, ok := severityByName(value); ok { - threshold = v - } else { - v, err := strconv.Atoi(value) - if err != nil { - return err - } - threshold = severity(v) - } - logging.stderrThreshold.set(threshold) - return nil -} - -func severityByName(s string) (severity, bool) { - s = strings.ToUpper(s) - for i, name := range severityName { - if name == s { - return severity(i), true - } - } - return 0, false -} - -// OutputStats tracks the number of output lines and bytes written. -type OutputStats struct { - lines int64 - bytes int64 -} - -// Lines returns the number of lines written. -func (s *OutputStats) Lines() int64 { - return atomic.LoadInt64(&s.lines) -} - -// Bytes returns the number of bytes written. -func (s *OutputStats) Bytes() int64 { - return atomic.LoadInt64(&s.bytes) -} - -// Stats tracks the number of lines of output and number of bytes -// per severity level. Values must be read with atomic.LoadInt64. -var Stats struct { - Info, Warning, Error OutputStats -} - -var severityStats = [numSeverity]*OutputStats{ - infoLog: &Stats.Info, - warningLog: &Stats.Warning, - errorLog: &Stats.Error, -} - -// Level is exported because it appears in the arguments to V and is -// the type of the v flag, which can be set programmatically. -// It's a distinct type because we want to discriminate it from logType. -// Variables of type level are only changed under logging.mu. -// The -v flag is read only with atomic ops, so the state of the logging -// module is consistent. - -// Level is treated as a sync/atomic int32. - -// Level specifies a level of verbosity for V logs. *Level implements -// flag.Value; the -v flag is of type Level and should be modified -// only through the flag.Value interface. -type Level int32 - -// get returns the value of the Level. -func (l *Level) get() Level { - return Level(atomic.LoadInt32((*int32)(l))) -} - -// set sets the value of the Level. -func (l *Level) set(val Level) { - atomic.StoreInt32((*int32)(l), int32(val)) -} - -// String is part of the flag.Value interface. -func (l *Level) String() string { - return strconv.FormatInt(int64(*l), 10) -} - -// Get is part of the flag.Value interface. -func (l *Level) Get() interface{} { - return *l -} - -// Set is part of the flag.Value interface. -func (l *Level) Set(value string) error { - v, err := strconv.Atoi(value) - if err != nil { - return err - } - logging.mu.Lock() - defer logging.mu.Unlock() - logging.setVState(Level(v), logging.vmodule.filter, false) - return nil -} - -// moduleSpec represents the setting of the -vmodule flag. -type moduleSpec struct { - filter []modulePat -} - -// modulePat contains a filter for the -vmodule flag. -// It holds a verbosity level and a file pattern to match. -type modulePat struct { - pattern string - literal bool // The pattern is a literal string - level Level -} - -// match reports whether the file matches the pattern. It uses a string -// comparison if the pattern contains no metacharacters. -func (m *modulePat) match(file string) bool { - if m.literal { - return file == m.pattern - } - match, _ := filepath.Match(m.pattern, file) - return match -} - -func (m *moduleSpec) String() string { - // Lock because the type is not atomic. TODO: clean this up. - logging.mu.Lock() - defer logging.mu.Unlock() - var b bytes.Buffer - for i, f := range m.filter { - if i > 0 { - b.WriteRune(',') - } - fmt.Fprintf(&b, "%s=%d", f.pattern, f.level) - } - return b.String() -} - -// Get is part of the (Go 1.2) flag.Getter interface. It always returns nil for this flag type since the -// struct is not exported. -func (m *moduleSpec) Get() interface{} { - return nil -} - -var errVmoduleSyntax = errors.New("syntax error: expect comma-separated list of filename=N") - -// Syntax: -vmodule=recordio=2,file=1,gfs*=3 -func (m *moduleSpec) Set(value string) error { - var filter []modulePat - for _, pat := range strings.Split(value, ",") { - if len(pat) == 0 { - // Empty strings such as from a trailing comma can be ignored. - continue - } - patLev := strings.Split(pat, "=") - if len(patLev) != 2 || len(patLev[0]) == 0 || len(patLev[1]) == 0 { - return errVmoduleSyntax - } - pattern := patLev[0] - v, err := strconv.Atoi(patLev[1]) - if err != nil { - return errors.New("syntax error: expect comma-separated list of filename=N") - } - if v < 0 { - return errors.New("negative value for vmodule level") - } - if v == 0 { - continue // Ignore. It's harmless but no point in paying the overhead. - } - // TODO: check syntax of filter? - filter = append(filter, modulePat{pattern, isLiteral(pattern), Level(v)}) - } - logging.mu.Lock() - defer logging.mu.Unlock() - logging.setVState(logging.verbosity, filter, true) - return nil -} - -// isLiteral reports whether the pattern is a literal string, that is, has no metacharacters -// that require filepath.Match to be called to match the pattern. -func isLiteral(pattern string) bool { - return !strings.ContainsAny(pattern, `\*?[]`) -} - -// traceLocation represents the setting of the -log_backtrace_at flag. -type traceLocation struct { - file string - line int -} - -// isSet reports whether the trace location has been specified. -// logging.mu is held. -func (t *traceLocation) isSet() bool { - return t.line > 0 -} - -// match reports whether the specified file and line matches the trace location. -// The argument file name is the full path, not the basename specified in the flag. -// logging.mu is held. -func (t *traceLocation) match(file string, line int) bool { - if t.line != line { - return false - } - if i := strings.LastIndex(file, "/"); i >= 0 { - file = file[i+1:] - } - return t.file == file -} - -func (t *traceLocation) String() string { - // Lock because the type is not atomic. TODO: clean this up. - logging.mu.Lock() - defer logging.mu.Unlock() - return fmt.Sprintf("%s:%d", t.file, t.line) -} - -// Get is part of the (Go 1.2) flag.Getter interface. It always returns nil for this flag type since the -// struct is not exported -func (t *traceLocation) Get() interface{} { - return nil -} - -var errTraceSyntax = errors.New("syntax error: expect file.go:234") - -// Syntax: -log_backtrace_at=gopherflakes.go:234 -// Note that unlike vmodule the file extension is included here. -func (t *traceLocation) Set(value string) error { - if value == "" { - // Unset. - t.line = 0 - t.file = "" - } - fields := strings.Split(value, ":") - if len(fields) != 2 { - return errTraceSyntax - } - file, line := fields[0], fields[1] - if !strings.Contains(file, ".") { - return errTraceSyntax - } - v, err := strconv.Atoi(line) - if err != nil { - return errTraceSyntax - } - if v <= 0 { - return errors.New("negative or zero value for level") - } - logging.mu.Lock() - defer logging.mu.Unlock() - t.line = v - t.file = file - return nil -} - -// flushSyncWriter is the interface satisfied by logging destinations. -type flushSyncWriter interface { - Flush() error - Sync() error - io.Writer -} - -func init() { - flag.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files") - flag.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files") - flag.Var(&logging.verbosity, "v", "log level for V logs") - flag.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr") - flag.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging") - flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace") - - // Default stderrThreshold is ERROR. - logging.stderrThreshold = errorLog - - logging.setVState(0, nil, false) - go logging.flushDaemon() -} - -// Flush flushes all pending log I/O. -func Flush() { - logging.lockAndFlushAll() -} - -// loggingT collects all the global state of the logging setup. -type loggingT struct { - // Boolean flags. Not handled atomically because the flag.Value interface - // does not let us avoid the =true, and that shorthand is necessary for - // compatibility. TODO: does this matter enough to fix? Seems unlikely. - toStderr bool // The -logtostderr flag. - alsoToStderr bool // The -alsologtostderr flag. - - // Level flag. Handled atomically. - stderrThreshold severity // The -stderrthreshold flag. - - // freeList is a list of byte buffers, maintained under freeListMu. - freeList *buffer - // freeListMu maintains the free list. It is separate from the main mutex - // so buffers can be grabbed and printed to without holding the main lock, - // for better parallelization. - freeListMu sync.Mutex - - // mu protects the remaining elements of this structure and is - // used to synchronize logging. - mu sync.Mutex - // file holds writer for each of the log types. - file [numSeverity]flushSyncWriter - // pcs is used in V to avoid an allocation when computing the caller's PC. - pcs [1]uintptr - // vmap is a cache of the V Level for each V() call site, identified by PC. - // It is wiped whenever the vmodule flag changes state. - vmap map[uintptr]Level - // filterLength stores the length of the vmodule filter chain. If greater - // than zero, it means vmodule is enabled. It may be read safely - // using sync.LoadInt32, but is only modified under mu. - filterLength int32 - // traceLocation is the state of the -log_backtrace_at flag. - traceLocation traceLocation - // These flags are modified only under lock, although verbosity may be fetched - // safely using atomic.LoadInt32. - vmodule moduleSpec // The state of the -vmodule flag. - verbosity Level // V logging level, the value of the -v flag/ -} - -// buffer holds a byte Buffer for reuse. The zero value is ready for use. -type buffer struct { - bytes.Buffer - tmp [64]byte // temporary byte array for creating headers. - next *buffer -} - -var logging loggingT - -// setVState sets a consistent state for V logging. -// l.mu is held. -func (l *loggingT) setVState(verbosity Level, filter []modulePat, setFilter bool) { - // Turn verbosity off so V will not fire while we are in transition. - logging.verbosity.set(0) - // Ditto for filter length. - atomic.StoreInt32(&logging.filterLength, 0) - - // Set the new filters and wipe the pc->Level map if the filter has changed. - if setFilter { - logging.vmodule.filter = filter - logging.vmap = make(map[uintptr]Level) - } - - // Things are consistent now, so enable filtering and verbosity. - // They are enabled in order opposite to that in V. - atomic.StoreInt32(&logging.filterLength, int32(len(filter))) - logging.verbosity.set(verbosity) -} - -// getBuffer returns a new, ready-to-use buffer. -func (l *loggingT) getBuffer() *buffer { - l.freeListMu.Lock() - b := l.freeList - if b != nil { - l.freeList = b.next - } - l.freeListMu.Unlock() - if b == nil { - b = new(buffer) - } else { - b.next = nil - b.Reset() - } - return b -} - -// putBuffer returns a buffer to the free list. -func (l *loggingT) putBuffer(b *buffer) { - if b.Len() >= 256 { - // Let big buffers die a natural death. - return - } - l.freeListMu.Lock() - b.next = l.freeList - l.freeList = b - l.freeListMu.Unlock() -} - -var timeNow = time.Now // Stubbed out for testing. - -/* -header formats a log header as defined by the C++ implementation. -It returns a buffer containing the formatted header and the user's file and line number. -The depth specifies how many stack frames above lives the source line to be identified in the log message. - -Log lines have this form: - Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... -where the fields are defined as follows: - L A single character, representing the log level (eg 'I' for INFO) - mm The month (zero padded; ie May is '05') - dd The day (zero padded) - hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds - threadid The space-padded thread ID as returned by GetTID() - file The file name - line The line number - msg The user-supplied message -*/ -func (l *loggingT) header(s severity, depth int) (*buffer, string, int) { - _, file, line, ok := runtime.Caller(3 + depth) - if !ok { - file = "???" - line = 1 - } else { - slash := strings.LastIndex(file, "/") - if slash >= 0 { - file = file[slash+1:] - } - } - return l.formatHeader(s, file, line), file, line -} - -// formatHeader formats a log header using the provided file name and line number. -func (l *loggingT) formatHeader(s severity, file string, line int) *buffer { - now := timeNow() - if line < 0 { - line = 0 // not a real line number, but acceptable to someDigits - } - if s > fatalLog { - s = infoLog // for safety. - } - buf := l.getBuffer() - - // Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand. - // It's worth about 3X. Fprintf is hard. - _, month, day := now.Date() - hour, minute, second := now.Clock() - // Lmmdd hh:mm:ss.uuuuuu threadid file:line] - buf.tmp[0] = severityChar[s] - buf.twoDigits(1, int(month)) - buf.twoDigits(3, day) - buf.tmp[5] = ' ' - buf.twoDigits(6, hour) - buf.tmp[8] = ':' - buf.twoDigits(9, minute) - buf.tmp[11] = ':' - buf.twoDigits(12, second) - buf.tmp[14] = '.' - buf.nDigits(6, 15, now.Nanosecond()/1000, '0') - buf.tmp[21] = ' ' - buf.nDigits(7, 22, pid, ' ') // TODO: should be TID - buf.tmp[29] = ' ' - buf.Write(buf.tmp[:30]) - buf.WriteString(file) - buf.tmp[0] = ':' - n := buf.someDigits(1, line) - buf.tmp[n+1] = ']' - buf.tmp[n+2] = ' ' - buf.Write(buf.tmp[:n+3]) - return buf -} - -// Some custom tiny helper functions to print the log header efficiently. - -const digits = "0123456789" - -// twoDigits formats a zero-prefixed two-digit integer at buf.tmp[i]. -func (buf *buffer) twoDigits(i, d int) { - buf.tmp[i+1] = digits[d%10] - d /= 10 - buf.tmp[i] = digits[d%10] -} - -// nDigits formats an n-digit integer at buf.tmp[i], -// padding with pad on the left. -// It assumes d >= 0. -func (buf *buffer) nDigits(n, i, d int, pad byte) { - j := n - 1 - for ; j >= 0 && d > 0; j-- { - buf.tmp[i+j] = digits[d%10] - d /= 10 - } - for ; j >= 0; j-- { - buf.tmp[i+j] = pad - } -} - -// someDigits formats a zero-prefixed variable-width integer at buf.tmp[i]. -func (buf *buffer) someDigits(i, d int) int { - // Print into the top, then copy down. We know there's space for at least - // a 10-digit number. - j := len(buf.tmp) - for { - j-- - buf.tmp[j] = digits[d%10] - d /= 10 - if d == 0 { - break - } - } - return copy(buf.tmp[i:], buf.tmp[j:]) -} - -func (l *loggingT) println(s severity, args ...interface{}) { - buf, file, line := l.header(s, 0) - fmt.Fprintln(buf, args...) - l.output(s, buf, file, line, false) -} - -func (l *loggingT) print(s severity, args ...interface{}) { - l.printDepth(s, 1, args...) -} - -func (l *loggingT) printDepth(s severity, depth int, args ...interface{}) { - buf, file, line := l.header(s, depth) - fmt.Fprint(buf, args...) - if buf.Bytes()[buf.Len()-1] != '\n' { - buf.WriteByte('\n') - } - l.output(s, buf, file, line, false) -} - -func (l *loggingT) printf(s severity, format string, args ...interface{}) { - buf, file, line := l.header(s, 0) - fmt.Fprintf(buf, format, args...) - if buf.Bytes()[buf.Len()-1] != '\n' { - buf.WriteByte('\n') - } - l.output(s, buf, file, line, false) -} - -// printWithFileLine behaves like print but uses the provided file and line number. If -// alsoLogToStderr is true, the log message always appears on standard error; it -// will also appear in the log file unless --logtostderr is set. -func (l *loggingT) printWithFileLine(s severity, file string, line int, alsoToStderr bool, args ...interface{}) { - buf := l.formatHeader(s, file, line) - fmt.Fprint(buf, args...) - if buf.Bytes()[buf.Len()-1] != '\n' { - buf.WriteByte('\n') - } - l.output(s, buf, file, line, alsoToStderr) -} - -// output writes the data to the log files and releases the buffer. -func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoToStderr bool) { - l.mu.Lock() - if l.traceLocation.isSet() { - if l.traceLocation.match(file, line) { - buf.Write(stacks(false)) - } - } - data := buf.Bytes() - if !flag.Parsed() { - os.Stderr.Write([]byte("ERROR: logging before flag.Parse: ")) - os.Stderr.Write(data) - } else if l.toStderr { - os.Stderr.Write(data) - } else { - if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() { - os.Stderr.Write(data) - } - if l.file[s] == nil { - if err := l.createFiles(s); err != nil { - os.Stderr.Write(data) // Make sure the message appears somewhere. - l.exit(err) - } - } - switch s { - case fatalLog: - l.file[fatalLog].Write(data) - fallthrough - case errorLog: - l.file[errorLog].Write(data) - fallthrough - case warningLog: - l.file[warningLog].Write(data) - fallthrough - case infoLog: - l.file[infoLog].Write(data) - } - } - if s == fatalLog { - // If we got here via Exit rather than Fatal, print no stacks. - if atomic.LoadUint32(&fatalNoStacks) > 0 { - l.mu.Unlock() - timeoutFlush(10 * time.Second) - os.Exit(1) - } - // Dump all goroutine stacks before exiting. - // First, make sure we see the trace for the current goroutine on standard error. - // If -logtostderr has been specified, the loop below will do that anyway - // as the first stack in the full dump. - if !l.toStderr { - os.Stderr.Write(stacks(false)) - } - // Write the stack trace for all goroutines to the files. - trace := stacks(true) - logExitFunc = func(error) {} // If we get a write error, we'll still exit below. - for log := fatalLog; log >= infoLog; log-- { - if f := l.file[log]; f != nil { // Can be nil if -logtostderr is set. - f.Write(trace) - } - } - l.mu.Unlock() - timeoutFlush(10 * time.Second) - os.Exit(255) // C++ uses -1, which is silly because it's anded with 255 anyway. - } - l.putBuffer(buf) - l.mu.Unlock() - if stats := severityStats[s]; stats != nil { - atomic.AddInt64(&stats.lines, 1) - atomic.AddInt64(&stats.bytes, int64(len(data))) - } -} - -// timeoutFlush calls Flush and returns when it completes or after timeout -// elapses, whichever happens first. This is needed because the hooks invoked -// by Flush may deadlock when glog.Fatal is called from a hook that holds -// a lock. -func timeoutFlush(timeout time.Duration) { - done := make(chan bool, 1) - go func() { - Flush() // calls logging.lockAndFlushAll() - done <- true - }() - select { - case <-done: - case <-time.After(timeout): - fmt.Fprintln(os.Stderr, "glog: Flush took longer than", timeout) - } -} - -// stacks is a wrapper for runtime.Stack that attempts to recover the data for all goroutines. -func stacks(all bool) []byte { - // We don't know how big the traces are, so grow a few times if they don't fit. Start large, though. - n := 10000 - if all { - n = 100000 - } - var trace []byte - for i := 0; i < 5; i++ { - trace = make([]byte, n) - nbytes := runtime.Stack(trace, all) - if nbytes < len(trace) { - return trace[:nbytes] - } - n *= 2 - } - return trace -} - -// logExitFunc provides a simple mechanism to override the default behavior -// of exiting on error. Used in testing and to guarantee we reach a required exit -// for fatal logs. Instead, exit could be a function rather than a method but that -// would make its use clumsier. -var logExitFunc func(error) - -// exit is called if there is trouble creating or writing log files. -// It flushes the logs and exits the program; there's no point in hanging around. -// l.mu is held. -func (l *loggingT) exit(err error) { - fmt.Fprintf(os.Stderr, "log: exiting because of error: %s\n", err) - // If logExitFunc is set, we do that instead of exiting. - if logExitFunc != nil { - logExitFunc(err) - return - } - l.flushAll() - os.Exit(2) -} - -// syncBuffer joins a bufio.Writer to its underlying file, providing access to the -// file's Sync method and providing a wrapper for the Write method that provides log -// file rotation. There are conflicting methods, so the file cannot be embedded. -// l.mu is held for all its methods. -type syncBuffer struct { - logger *loggingT - *bufio.Writer - file *os.File - sev severity - nbytes uint64 // The number of bytes written to this file -} - -func (sb *syncBuffer) Sync() error { - return sb.file.Sync() -} - -func (sb *syncBuffer) Write(p []byte) (n int, err error) { - if sb.nbytes+uint64(len(p)) >= MaxSize { - if err := sb.rotateFile(time.Now()); err != nil { - sb.logger.exit(err) - } - } - n, err = sb.Writer.Write(p) - sb.nbytes += uint64(n) - if err != nil { - sb.logger.exit(err) - } - return -} - -// rotateFile closes the syncBuffer's file and starts a new one. -func (sb *syncBuffer) rotateFile(now time.Time) error { - if sb.file != nil { - sb.Flush() - sb.file.Close() - } - var err error - sb.file, _, err = create(severityName[sb.sev], now) - sb.nbytes = 0 - if err != nil { - return err - } - - sb.Writer = bufio.NewWriterSize(sb.file, bufferSize) - - // Write header. - var buf bytes.Buffer - fmt.Fprintf(&buf, "Log file created at: %s\n", now.Format("2006/01/02 15:04:05")) - fmt.Fprintf(&buf, "Running on machine: %s\n", host) - fmt.Fprintf(&buf, "Binary: Built with %s %s for %s/%s\n", runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH) - fmt.Fprintf(&buf, "Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg\n") - n, err := sb.file.Write(buf.Bytes()) - sb.nbytes += uint64(n) - return err -} - -// bufferSize sizes the buffer associated with each log file. It's large -// so that log records can accumulate without the logging thread blocking -// on disk I/O. The flushDaemon will block instead. -const bufferSize = 256 * 1024 - -// createFiles creates all the log files for severity from sev down to infoLog. -// l.mu is held. -func (l *loggingT) createFiles(sev severity) error { - now := time.Now() - // Files are created in decreasing severity order, so as soon as we find one - // has already been created, we can stop. - for s := sev; s >= infoLog && l.file[s] == nil; s-- { - sb := &syncBuffer{ - logger: l, - sev: s, - } - if err := sb.rotateFile(now); err != nil { - return err - } - l.file[s] = sb - } - return nil -} - -const flushInterval = 30 * time.Second - -// flushDaemon periodically flushes the log file buffers. -func (l *loggingT) flushDaemon() { - for range time.NewTicker(flushInterval).C { - l.lockAndFlushAll() - } -} - -// lockAndFlushAll is like flushAll but locks l.mu first. -func (l *loggingT) lockAndFlushAll() { - l.mu.Lock() - l.flushAll() - l.mu.Unlock() -} - -// flushAll flushes all the logs and attempts to "sync" their data to disk. -// l.mu is held. -func (l *loggingT) flushAll() { - // Flush from fatal down, in case there's trouble flushing. - for s := fatalLog; s >= infoLog; s-- { - file := l.file[s] - if file != nil { - file.Flush() // ignore error - file.Sync() // ignore error - } - } -} - -// CopyStandardLogTo arranges for messages written to the Go "log" package's -// default logs to also appear in the Google logs for the named and lower -// severities. Subsequent changes to the standard log's default output location -// or format may break this behavior. -// -// Valid names are "INFO", "WARNING", "ERROR", and "FATAL". If the name is not -// recognized, CopyStandardLogTo panics. -func CopyStandardLogTo(name string) { - sev, ok := severityByName(name) - if !ok { - panic(fmt.Sprintf("log.CopyStandardLogTo(%q): unrecognized severity name", name)) - } - // Set a log format that captures the user's file and line: - // d.go:23: message - stdLog.SetFlags(stdLog.Lshortfile) - stdLog.SetOutput(logBridge(sev)) -} - -// logBridge provides the Write method that enables CopyStandardLogTo to connect -// Go's standard logs to the logs provided by this package. -type logBridge severity - -// Write parses the standard logging line and passes its components to the -// logger for severity(lb). -func (lb logBridge) Write(b []byte) (n int, err error) { - var ( - file = "???" - line = 1 - text string - ) - // Split "d.go:23: message" into "d.go", "23", and "message". - if parts := bytes.SplitN(b, []byte{':'}, 3); len(parts) != 3 || len(parts[0]) < 1 || len(parts[2]) < 1 { - text = fmt.Sprintf("bad log format: %s", b) - } else { - file = string(parts[0]) - text = string(parts[2][1:]) // skip leading space - line, err = strconv.Atoi(string(parts[1])) - if err != nil { - text = fmt.Sprintf("bad line number: %s", b) - line = 1 - } - } - // printWithFileLine with alsoToStderr=true, so standard log messages - // always appear on standard error. - logging.printWithFileLine(severity(lb), file, line, true, text) - return len(b), nil -} - -// setV computes and remembers the V level for a given PC -// when vmodule is enabled. -// File pattern matching takes the basename of the file, stripped -// of its .go suffix, and uses filepath.Match, which is a little more -// general than the *? matching used in C++. -// l.mu is held. -func (l *loggingT) setV(pc uintptr) Level { - fn := runtime.FuncForPC(pc) - file, _ := fn.FileLine(pc) - // The file is something like /a/b/c/d.go. We want just the d. - if strings.HasSuffix(file, ".go") { - file = file[:len(file)-3] - } - if slash := strings.LastIndex(file, "/"); slash >= 0 { - file = file[slash+1:] - } - for _, filter := range l.vmodule.filter { - if filter.match(file) { - l.vmap[pc] = filter.level - return filter.level - } - } - l.vmap[pc] = 0 - return 0 -} - -// Verbose is a boolean type that implements Infof (like Printf) etc. -// See the documentation of V for more information. -type Verbose bool - -// V reports whether verbosity at the call site is at least the requested level. -// The returned value is a boolean of type Verbose, which implements Info, Infoln -// and Infof. These methods will write to the Info log if called. -// Thus, one may write either -// if glog.V(2) { glog.Info("log this") } -// or -// glog.V(2).Info("log this") -// The second form is shorter but the first is cheaper if logging is off because it does -// not evaluate its arguments. -// -// Whether an individual call to V generates a log record depends on the setting of -// the -v and --vmodule flags; both are off by default. If the level in the call to -// V is at most the value of -v, or of -vmodule for the source file containing the -// call, the V call will log. -func V(level Level) Verbose { - // This function tries hard to be cheap unless there's work to do. - // The fast path is two atomic loads and compares. - - // Here is a cheap but safe test to see if V logging is enabled globally. - if logging.verbosity.get() >= level { - return Verbose(true) - } - - // It's off globally but it vmodule may still be set. - // Here is another cheap but safe test to see if vmodule is enabled. - if atomic.LoadInt32(&logging.filterLength) > 0 { - // Now we need a proper lock to use the logging structure. The pcs field - // is shared so we must lock before accessing it. This is fairly expensive, - // but if V logging is enabled we're slow anyway. - logging.mu.Lock() - defer logging.mu.Unlock() - if runtime.Callers(2, logging.pcs[:]) == 0 { - return Verbose(false) - } - v, ok := logging.vmap[logging.pcs[0]] - if !ok { - v = logging.setV(logging.pcs[0]) - } - return Verbose(v >= level) - } - return Verbose(false) -} - -// Info is equivalent to the global Info function, guarded by the value of v. -// See the documentation of V for usage. -func (v Verbose) Info(args ...interface{}) { - if v { - logging.print(infoLog, args...) - } -} - -// Infoln is equivalent to the global Infoln function, guarded by the value of v. -// See the documentation of V for usage. -func (v Verbose) Infoln(args ...interface{}) { - if v { - logging.println(infoLog, args...) - } -} - -// Infof is equivalent to the global Infof function, guarded by the value of v. -// See the documentation of V for usage. -func (v Verbose) Infof(format string, args ...interface{}) { - if v { - logging.printf(infoLog, format, args...) - } -} - -// Info logs to the INFO log. -// Arguments are handled in the manner of fmt.Print; a newline is appended if missing. -func Info(args ...interface{}) { - logging.print(infoLog, args...) -} - -// InfoDepth acts as Info but uses depth to determine which call frame to log. -// InfoDepth(0, "msg") is the same as Info("msg"). -func InfoDepth(depth int, args ...interface{}) { - logging.printDepth(infoLog, depth, args...) -} - -// Infoln logs to the INFO log. -// Arguments are handled in the manner of fmt.Println; a newline is appended if missing. -func Infoln(args ...interface{}) { - logging.println(infoLog, args...) -} - -// Infof logs to the INFO log. -// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. -func Infof(format string, args ...interface{}) { - logging.printf(infoLog, format, args...) -} - -// Warning logs to the WARNING and INFO logs. -// Arguments are handled in the manner of fmt.Print; a newline is appended if missing. -func Warning(args ...interface{}) { - logging.print(warningLog, args...) -} - -// WarningDepth acts as Warning but uses depth to determine which call frame to log. -// WarningDepth(0, "msg") is the same as Warning("msg"). -func WarningDepth(depth int, args ...interface{}) { - logging.printDepth(warningLog, depth, args...) -} - -// Warningln logs to the WARNING and INFO logs. -// Arguments are handled in the manner of fmt.Println; a newline is appended if missing. -func Warningln(args ...interface{}) { - logging.println(warningLog, args...) -} - -// Warningf logs to the WARNING and INFO logs. -// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. -func Warningf(format string, args ...interface{}) { - logging.printf(warningLog, format, args...) -} - -// Error logs to the ERROR, WARNING, and INFO logs. -// Arguments are handled in the manner of fmt.Print; a newline is appended if missing. -func Error(args ...interface{}) { - logging.print(errorLog, args...) -} - -// ErrorDepth acts as Error but uses depth to determine which call frame to log. -// ErrorDepth(0, "msg") is the same as Error("msg"). -func ErrorDepth(depth int, args ...interface{}) { - logging.printDepth(errorLog, depth, args...) -} - -// Errorln logs to the ERROR, WARNING, and INFO logs. -// Arguments are handled in the manner of fmt.Println; a newline is appended if missing. -func Errorln(args ...interface{}) { - logging.println(errorLog, args...) -} - -// Errorf logs to the ERROR, WARNING, and INFO logs. -// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. -func Errorf(format string, args ...interface{}) { - logging.printf(errorLog, format, args...) -} - -// Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, -// including a stack trace of all running goroutines, then calls os.Exit(255). -// Arguments are handled in the manner of fmt.Print; a newline is appended if missing. -func Fatal(args ...interface{}) { - logging.print(fatalLog, args...) -} - -// FatalDepth acts as Fatal but uses depth to determine which call frame to log. -// FatalDepth(0, "msg") is the same as Fatal("msg"). -func FatalDepth(depth int, args ...interface{}) { - logging.printDepth(fatalLog, depth, args...) -} - -// Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, -// including a stack trace of all running goroutines, then calls os.Exit(255). -// Arguments are handled in the manner of fmt.Println; a newline is appended if missing. -func Fatalln(args ...interface{}) { - logging.println(fatalLog, args...) -} - -// Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, -// including a stack trace of all running goroutines, then calls os.Exit(255). -// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. -func Fatalf(format string, args ...interface{}) { - logging.printf(fatalLog, format, args...) -} - -// fatalNoStacks is non-zero if we are to exit without dumping goroutine stacks. -// It allows Exit and relatives to use the Fatal logs. -var fatalNoStacks uint32 - -// Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). -// Arguments are handled in the manner of fmt.Print; a newline is appended if missing. -func Exit(args ...interface{}) { - atomic.StoreUint32(&fatalNoStacks, 1) - logging.print(fatalLog, args...) -} - -// ExitDepth acts as Exit but uses depth to determine which call frame to log. -// ExitDepth(0, "msg") is the same as Exit("msg"). -func ExitDepth(depth int, args ...interface{}) { - atomic.StoreUint32(&fatalNoStacks, 1) - logging.printDepth(fatalLog, depth, args...) -} - -// Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). -func Exitln(args ...interface{}) { - atomic.StoreUint32(&fatalNoStacks, 1) - logging.println(fatalLog, args...) -} - -// Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). -// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. -func Exitf(format string, args ...interface{}) { - atomic.StoreUint32(&fatalNoStacks, 1) - logging.printf(fatalLog, format, args...) -} diff --git a/vendor/github.com/golang/glog/glog_file.go b/vendor/github.com/golang/glog/glog_file.go deleted file mode 100644 index 65075d2811..0000000000 --- a/vendor/github.com/golang/glog/glog_file.go +++ /dev/null @@ -1,124 +0,0 @@ -// Go support for leveled logs, analogous to https://code.google.com/p/google-glog/ -// -// Copyright 2013 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// File I/O for logs. - -package glog - -import ( - "errors" - "flag" - "fmt" - "os" - "os/user" - "path/filepath" - "strings" - "sync" - "time" -) - -// MaxSize is the maximum size of a log file in bytes. -var MaxSize uint64 = 1024 * 1024 * 1800 - -// logDirs lists the candidate directories for new log files. -var logDirs []string - -// If non-empty, overrides the choice of directory in which to write logs. -// See createLogDirs for the full list of possible destinations. -var logDir = flag.String("log_dir", "", "If non-empty, write log files in this directory") - -func createLogDirs() { - if *logDir != "" { - logDirs = append(logDirs, *logDir) - } - logDirs = append(logDirs, os.TempDir()) -} - -var ( - pid = os.Getpid() - program = filepath.Base(os.Args[0]) - host = "unknownhost" - userName = "unknownuser" -) - -func init() { - h, err := os.Hostname() - if err == nil { - host = shortHostname(h) - } - - current, err := user.Current() - if err == nil { - userName = current.Username - } - - // Sanitize userName since it may contain filepath separators on Windows. - userName = strings.Replace(userName, `\`, "_", -1) -} - -// shortHostname returns its argument, truncating at the first period. -// For instance, given "www.google.com" it returns "www". -func shortHostname(hostname string) string { - if i := strings.Index(hostname, "."); i >= 0 { - return hostname[:i] - } - return hostname -} - -// logName returns a new log file name containing tag, with start time t, and -// the name for the symlink for tag. -func logName(tag string, t time.Time) (name, link string) { - name = fmt.Sprintf("%s.%s.%s.log.%s.%04d%02d%02d-%02d%02d%02d.%d", - program, - host, - userName, - tag, - t.Year(), - t.Month(), - t.Day(), - t.Hour(), - t.Minute(), - t.Second(), - pid) - return name, program + "." + tag -} - -var onceLogDirs sync.Once - -// create creates a new log file and returns the file and its filename, which -// contains tag ("INFO", "FATAL", etc.) and t. If the file is created -// successfully, create also attempts to update the symlink for that tag, ignoring -// errors. -func create(tag string, t time.Time) (f *os.File, filename string, err error) { - onceLogDirs.Do(createLogDirs) - if len(logDirs) == 0 { - return nil, "", errors.New("log: no log dirs") - } - name, link := logName(tag, t) - var lastErr error - for _, dir := range logDirs { - fname := filepath.Join(dir, name) - f, err := os.Create(fname) - if err == nil { - symlink := filepath.Join(dir, link) - os.Remove(symlink) // ignore err - os.Symlink(name, symlink) // ignore err - return f, fname, nil - } - lastErr = err - } - return nil, "", fmt.Errorf("log: cannot create log: %v", lastErr) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 5a1a7f00de..f818668a2a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -426,8 +426,7 @@ github.com/gofrs/flock github.com/gogo/protobuf/proto github.com/gogo/protobuf/sortkeys # github.com/golang/glog v1.0.0 -## explicit; go 1.11 -github.com/golang/glog +## explicit # github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da ## explicit github.com/golang/groupcache/lru