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

Remove package server subscription #942

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions cmd/olm/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package main

import (
"time"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
)

const (
pollInterval = 1 * time.Second
pollDuration = 5 * time.Minute
)

type checkResourceFunc func() error
type deleteResourceFunc func() error

func cleanup(logger *logrus.Logger, c operatorclient.ClientInterface, crc versioned.Interface) {
if err := waitForDelete(checkCatalogSource(crc, "olm-operators"), deleteCatalogSource(crc, "olm-operators")); err != nil {
logger.WithError(err).Fatal("couldn't clean previous release")
}

if err := waitForDelete(checkConfigMap(c, "olm-operators"), deleteConfigMap(c, "olm-operators")); err != nil {
logger.WithError(err).Fatal("couldn't clean previous release")
}

if err := waitForDelete(checkSubscription(crc, "packageserver"), deleteSubscription(crc, "packageserver")); err != nil {
logger.WithError(err).Fatal("couldn't clean previous release")
}

if err := waitForDelete(checkClusterServiceVersion(crc, "packageserver.v0.10.0"), deleteClusterServiceVersion(crc, "packageserver.v0.10.0")); err != nil {
logger.WithError(err).Fatal("couldn't clean previous release")
}

if err := waitForDelete(checkClusterServiceVersion(crc, "packageserver.v0.9.0"), deleteClusterServiceVersion(crc, "packageserver.v0.9.0")); err != nil {
logger.WithError(err).Fatal("couldn't clean previous release")
}
}

func waitForDelete(checkResource checkResourceFunc, deleteResource deleteResourceFunc) error {
if err := checkResource(); err != nil && errors.IsNotFound(err) {
return nil
}
if err := deleteResource(); err != nil {
return err
}
var err error
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
err := checkResource()
if errors.IsNotFound(err) {
return true, nil
}
if err != nil {
return false, err
}
return false, nil
})

return err
}

func checkClusterServiceVersion(crc versioned.Interface, name string) checkResourceFunc {
return func() error {
_, err := crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Get(name, metav1.GetOptions{})
return err
}
}

func deleteClusterServiceVersion(crc versioned.Interface, name string) deleteResourceFunc {
return func() error {
return crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Delete(name, metav1.NewDeleteOptions(0))
}
}

func checkSubscription(crc versioned.Interface, name string) checkResourceFunc {
return func() error {
_, err := crc.OperatorsV1alpha1().Subscriptions(*namespace).Get(name, metav1.GetOptions{})
return err
}
}

func deleteSubscription(crc versioned.Interface, name string) deleteResourceFunc {
return func() error {
return crc.OperatorsV1alpha1().Subscriptions(*namespace).Delete(name, metav1.NewDeleteOptions(0))
}
}

func checkConfigMap(c operatorclient.ClientInterface, name string) checkResourceFunc {
return func() error {
_, err := c.KubernetesInterface().CoreV1().ConfigMaps(*namespace).Get(name, metav1.GetOptions{})
return err
}
}

func deleteConfigMap(c operatorclient.ClientInterface, name string) deleteResourceFunc {
return func() error {
return c.KubernetesInterface().CoreV1().ConfigMaps(*namespace).Delete(name, metav1.NewDeleteOptions(0))
}
}

func checkCatalogSource(crc versioned.Interface, name string) checkResourceFunc {
return func() error {
_, err := crc.OperatorsV1alpha1().CatalogSources(*namespace).Get(name, metav1.GetOptions{})
return err
}
}

func deleteCatalogSource(crc versioned.Interface, name string) deleteResourceFunc {
return func() error {
return crc.OperatorsV1alpha1().CatalogSources(*namespace).Delete(name, metav1.NewDeleteOptions(0))
}
}
8 changes: 7 additions & 1 deletion cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ var (

profiling = flag.Bool(
"profiling", false, "serve profiling data (on port 8080)")

namespace = flag.String(
"namespace", "", "namespace where cleanup runs")
)

func init() {
Expand Down Expand Up @@ -165,6 +168,8 @@ func main() {
log.Fatalf("error configuring client: %s", err.Error())
}

cleanup(logger, opClient, crClient)

// Create a new instance of the operator.
op, err := olm.NewOperator(
ctx,
Expand All @@ -176,7 +181,8 @@ func main() {
olm.WithRestConfig(config),
)
if err != nil {
log.Fatalf("error configuring operator: %s", err.Error())
log.WithError(err).Fatalf("error configuring operator")
return
}

op.Run(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ spec:
command:
- /bin/olm
args:
- -namespace
- ${OPERATOR_NAMESPACE}
{{- if .Values.watchedNamespaces }}
- -watchedNamespaces
- {{ .Values.watchedNamespaces }}
Expand Down
11 changes: 0 additions & 11 deletions deploy/chart/templates/0000_50_olm_11-olm-operators.configmap.yaml

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{{ if and .Values.installType (eq .Values.installType "ocp") }}
{{- include "packageserver.clusterserviceversion" . }}
{{- end }}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
metadata:
name: packageserver.v{{ .Chart.Version }}
name: packageserver
namespace: {{ .Values.namespace }}
labels:
olm.version: {{ .Chart.Version }}
{{- if .Values.writePackageServerStatusName }}
olm.clusteroperator.name: {{ .Values.writePackageServerStatusName }}
{{- end }}
Expand Down Expand Up @@ -34,7 +35,7 @@ spec:
strategy: deployment
spec:
clusterPermissions:
- serviceAccountName: packageserver
- serviceAccountName: olm-operator-serviceaccount
rules:
- apiGroups:
- authorization.k8s.io
Expand Down
2 changes: 1 addition & 1 deletion deploy/chart/templates/_packageserver.deployment-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
labels:
app: packageserver
spec:
serviceAccountName: packageserver
serviceAccountName: olm-operator-serviceaccount
{{- if and .Values.installType (eq .Values.installType "ocp") }}
priorityClassName: "system-cluster-critical"
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions manifests/0000_50_olm_07-olm-operator.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
command:
- /bin/olm
args:
- -namespace
- ${OPERATOR_NAMESPACE}
- -writeStatusName
- operator-lifecycle-manager
- -writePackageServerStatusName
Expand Down
Loading