Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jira PSAP-1288: NTO operand cleanup #970

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions Dockerfile
Expand Up @@ -21,11 +21,11 @@ COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_o
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/performance-profile-creator /usr/bin/
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/gather-sysinfo /usr/bin/
COPY manifests/*.yaml manifests/image-references /manifests/
ENV APP_ROOT=/var/lib/tuned
ENV APP_ROOT=/var/lib/ocp-tuned
ENV PATH=${APP_ROOT}/bin:${PATH}
ENV HOME=${APP_ROOT}
ENV SYSTEMD_IGNORE_CHROOT=1
WORKDIR ${APP_ROOT}
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/openshift-tuned /usr/bin/
COPY --from=tuned /root/assets ${APP_ROOT}
COPY --from=tuned /root/rpmbuild/RPMS/noarch /root/rpms
RUN INSTALL_PKGS=" \
Expand All @@ -36,7 +36,8 @@ RUN INSTALL_PKGS=" \
rpm -V $INSTALL_PKGS && \
dnf --setopt=tsflags=nodocs -y install /root/rpms/*.rpm && \
find /root/rpms -name \*.rpm -exec basename {} .rpm \; | xargs rpm -e --justdb && \
rm -rf /var/lib/tuned/tuned && \
rm -rf /var/lib/ocp-tuned/{tuned,performanceprofile} && \
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|' /etc/tuned/tuned-main.conf && \
touch /etc/sysctl.conf $APP_ROOT/provider && \
dnf clean all && \
rm -rf /var/cache/yum ~/patches /root/rpms && \
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile.rhel8
Expand Up @@ -8,20 +8,21 @@ COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_o
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/performance-profile-creator /usr/bin/
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/gather-sysinfo /usr/bin/
COPY manifests/*.yaml manifests/image-references /manifests/
ENV APP_ROOT=/var/lib/tuned
ENV APP_ROOT=/var/lib/ocp-tuned
ENV PATH=${APP_ROOT}/bin:${PATH}
ENV HOME=${APP_ROOT}
ENV SYSTEMD_IGNORE_CHROOT=1
WORKDIR ${APP_ROOT}
COPY assets ${APP_ROOT}
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/openshift-tuned /usr/bin/
RUN INSTALL_PKGS=" \
tuned tuned-profiles-atomic tuned-profiles-cpu-partitioning tuned-profiles-mssql tuned-profiles-nfv tuned-profiles-nfv-guest \
tuned-profiles-nfv-host tuned-profiles-openshift tuned-profiles-oracle tuned-profiles-postgresql tuned-profiles-realtime \
tuned-profiles-sap tuned-profiles-sap-hana tuned-profiles-spectrumscale \
nmap-ncat procps-ng pciutils" && \
mkdir -p /etc/grub.d/ /boot && \
dnf install --setopt=tsflags=nodocs -y $INSTALL_PKGS && \
rm -rf /var/lib/tuned/tuned && \
rm -rf /var/lib/ocp-tuned/{tuned,performanceprofile} && \
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|' /etc/tuned/tuned-main.conf && \
touch /etc/sysctl.conf $APP_ROOT/provider && \
dnf clean all && \
rm -rf /var/cache/yum ~/patches /root/rpms && \
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile.rhel9
Expand Up @@ -8,20 +8,21 @@ COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_o
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/performance-profile-creator /usr/bin/
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/gather-sysinfo /usr/bin/
COPY manifests/*.yaml manifests/image-references /manifests/
ENV APP_ROOT=/var/lib/tuned
ENV APP_ROOT=/var/lib/ocp-tuned
ENV PATH=${APP_ROOT}/bin:${PATH}
ENV HOME=${APP_ROOT}
ENV SYSTEMD_IGNORE_CHROOT=1
WORKDIR ${APP_ROOT}
COPY assets ${APP_ROOT}
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/openshift-tuned /usr/bin/
RUN INSTALL_PKGS=" \
tuned tuned-profiles-atomic tuned-profiles-cpu-partitioning tuned-profiles-mssql tuned-profiles-nfv tuned-profiles-nfv-guest \
tuned-profiles-nfv-host tuned-profiles-openshift tuned-profiles-oracle tuned-profiles-postgresql tuned-profiles-realtime \
tuned-profiles-sap tuned-profiles-sap-hana tuned-profiles-spectrumscale \
nmap-ncat procps-ng pciutils" && \
mkdir -p /etc/grub.d/ /boot && \
dnf install --setopt=tsflags=nodocs -y $INSTALL_PKGS && \
rm -rf /var/lib/tuned/tuned && \
rm -rf /var/lib/ocp-tuned/{tuned,performanceprofile} && \
sed -Ei 's|^#?\s*enable_unix_socket\s*=.*$|enable_unix_socket = 1|;s|^#?\s*rollback\s*=.*$|rollback = not_on_exit|' /etc/tuned/tuned-main.conf && \
touch /etc/sysctl.conf $APP_ROOT/provider && \
dnf clean all && \
rm -rf /var/cache/yum ~/patches /root/rpms && \
Expand Down
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -63,7 +63,6 @@ clone-tuned:

build: $(BINDATA) pkg/generated build-performance-profile-creator build-gather-sysinfo
$(GO_BUILD_RECIPE)
ln -sf $(PACKAGE_BIN) $(OUT_DIR)/openshift-tuned

$(BINDATA): $(GOBINDATA_BIN) $(ASSETS)
$(GOBINDATA_BIN) -mode 420 -modtime 1 -pkg manifests -o $(BINDATA) assets/...
Expand Down
32 changes: 0 additions & 32 deletions assets/bin/run

This file was deleted.

2 changes: 1 addition & 1 deletion assets/tuned/manifests/default-cr-tuned.yaml
Expand Up @@ -9,7 +9,7 @@ spec:
data: |
[main]
summary=Optimize systems running OpenShift (provider specific parent profile)
include=-provider-${f:exec:cat:/var/lib/tuned/provider},openshift
include=-provider-${f:exec:cat:/var/lib/ocp-tuned/provider},openshift
recommend:
- profile: "openshift-control-plane"
priority: 30
Expand Down
15 changes: 3 additions & 12 deletions assets/tuned/manifests/ds-tuned.yaml
Expand Up @@ -22,7 +22,7 @@ spec:
spec:
serviceAccountName: tuned
containers:
- command: ["/var/lib/tuned/bin/run","start"]
- command: ["/usr/bin/cluster-node-tuning-operator","openshift-tuned","--in-cluster","-v=0"]
resources:
requests:
cpu: 10m
Expand All @@ -35,9 +35,6 @@ spec:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: FallbackToLogsOnError
volumeMounts:
- mountPath: /var/lib/tuned/profiles-data
name: var-lib-tuned-profiles-data
mountPropagation: HostToContainer
- mountPath: /etc/modprobe.d
name: etc-modprobe-d
mountPropagation: HostToContainer
Expand Down Expand Up @@ -91,6 +88,8 @@ spec:
value: "600"
- name: RELEASE_VERSION
value: ""
- name: CLUSTER_NODE_TUNED_IMAGE
value: ${CLUSTER_NODE_TUNED_IMAGE}
volumes:
- hostPath:
path: /etc/modprobe.d
Expand Down Expand Up @@ -136,14 +135,6 @@ spec:
hostPath:
path: /
type: Directory
- configMap:
defaultMode: 0644
items:
- key: tuned-profiles-data
path: tuned-profiles.yaml
name: tuned-profiles
optional: true
name: var-lib-tuned-profiles-data
dnsPolicy: ClusterFirst
nodeSelector:
kubernetes.io/os: linux
Expand Down
39 changes: 11 additions & 28 deletions cmd/cluster-node-tuning-operator/main.go
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"time"

Expand Down Expand Up @@ -47,8 +46,7 @@ import (
"github.com/openshift/cluster-node-tuning-operator/pkg/metrics"
"github.com/openshift/cluster-node-tuning-operator/pkg/operator"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/cmd/render"
"github.com/openshift/cluster-node-tuning-operator/pkg/signals"
"github.com/openshift/cluster-node-tuning-operator/pkg/tuned"
"github.com/openshift/cluster-node-tuning-operator/pkg/tuned/cmd/operand"
tunedrender "github.com/openshift/cluster-node-tuning-operator/pkg/tuned/cmd/render"
"github.com/openshift/cluster-node-tuning-operator/pkg/util"
"github.com/openshift/cluster-node-tuning-operator/version"
Expand Down Expand Up @@ -93,13 +91,15 @@ var rootCmd = &cobra.Command{
},
}

var enableLeaderElection bool
var showVersionAndExit bool
var (
enableLeaderElection bool
showVersionAndExit bool
)

func prepareCommands() {
rootCmd.PersistentFlags().BoolVar(&enableLeaderElection, "enable-leader-election", true,
rootCmd.Flags().BoolVar(&enableLeaderElection, "enable-leader-election", true,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
rootCmd.PersistentFlags().BoolVar(&showVersionAndExit, "version", false,
rootCmd.Flags().BoolVar(&showVersionAndExit, "version", false,
"Show program version and exit.")

// Include the klog command line arguments
Expand All @@ -110,6 +110,7 @@ func prepareCommands() {
rootCmd.AddCommand(render.NewRenderCommand())
rootCmd.AddCommand(tunedrender.NewRenderBootCmdMCCommand())
}
rootCmd.AddCommand(operand.NewTunedCommand())
}

func operatorRun() {
Expand Down Expand Up @@ -205,17 +206,6 @@ func operatorRun() {
}
}

func tunedOperandRun() {
var boolVersion bool
flag.BoolVar(&boolVersion, "version", false, "show program version and exit")

// flag.Parse is called from within tuned.Run -> parseCmdOpts
// but the version flag variable is inherited from here..

stopCh := signals.SetupSignalHandler()
tuned.Run(stopCh, &boolVersion, version.Version)
}

// Uninstall PAO OLM operator since PAO is shipped
// as a core operator from 4.11.
// This is relevant for any upgrade path of an OpenShift cluster
Expand Down Expand Up @@ -376,15 +366,8 @@ func setupFeatureGates(ctx context.Context, config *rest.Config, operatorNamespa
}

func main() {
runAs := filepath.Base(os.Args[0])

switch runAs {
case version.OperatorFilename:
prepareCommands()
_ = rootCmd.Execute()
case version.OperandFilename:
tunedOperandRun()
default:
klog.Fatalf("application should be run as \"%s\" or \"%s\"", version.OperatorFilename, version.OperandFilename)
prepareCommands()
if err := rootCmd.Execute(); err != nil {
klog.Fatal(err)
}
}
6 changes: 4 additions & 2 deletions pkg/manifests/manifests.go
Expand Up @@ -76,9 +76,11 @@ func TunedDaemonSet() *appsv1.DaemonSet {
ds.Spec.Template.Spec.Containers[0].Image = imageTuned

for i := range ds.Spec.Template.Spec.Containers[0].Env {
if ds.Spec.Template.Spec.Containers[0].Env[i].Name == "RELEASE_VERSION" {
switch ds.Spec.Template.Spec.Containers[0].Env[i].Name {
case "RELEASE_VERSION":
ds.Spec.Template.Spec.Containers[0].Env[i].Value = os.Getenv("RELEASE_VERSION")
break
case "CLUSTER_NODE_TUNED_IMAGE":
ds.Spec.Template.Spec.Containers[0].Env[i].Value = os.Getenv("CLUSTER_NODE_TUNED_IMAGE")
}
}

Expand Down
78 changes: 78 additions & 0 deletions pkg/tuned/cmd/operand/cmd.go
@@ -0,0 +1,78 @@
/*

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 operand

import (
"flag"

"github.com/openshift/cluster-node-tuning-operator/pkg/signals"
"github.com/openshift/cluster-node-tuning-operator/pkg/tuned"
"github.com/openshift/cluster-node-tuning-operator/version"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/klog/v2"
)

type tunedOpts struct {
inCluster bool
}

func NewTunedCommand() *cobra.Command {
tunedOpts := tunedOpts{}

cmd := &cobra.Command{
Use: version.OperandFilename,
Short: "Start NTO operand",
Run: func(cmd *cobra.Command, args []string) {
if err := tunedOpts.Validate(); err != nil {
klog.Fatal(err)
}

if err := tunedOpts.Run(); err != nil {
klog.Fatal(err)
}
},
}

addKlogFlags(cmd)
tunedOpts.AddFlags(cmd.Flags())
return cmd
}

func (t *tunedOpts) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&t.inCluster, "in-cluster", true, "In-cluster operand run.")
}

func addKlogFlags(cmd *cobra.Command) {
fs := flag.NewFlagSet("", flag.PanicOnError)
klog.InitFlags(fs)
cmd.Flags().AddGoFlagSet(fs)
}

func (t *tunedOpts) Validate() error {
return nil
}

func (t *tunedOpts) Run() error {
return tunedOperandRun(t.inCluster)
}

func tunedOperandRun(inCluster bool) error {
stopCh := signals.SetupSignalHandler()
return tuned.RunOperand(stopCh, version.Version, inCluster)
}