Skip to content

Commit

Permalink
Merge pull request #678 from redhat-marketplace/release/2.17.2
Browse files Browse the repository at this point in the history
Release/2.17.2
  • Loading branch information
dacleyra authored Sep 25, 2024
2 parents 1d1d4ca + 4140785 commit 7403d50
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 10 deletions.
120 changes: 120 additions & 0 deletions hack/must-gather.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash
set -x

# IBM Metrics Operator / Data Reporter Operator Namespace
IMO_NAMESPACE="${IMO_NAMESPACE:-ibm-software-central}"

# IBM Licensing Service Namespace
LS_NAMESPACE="${LS_NAMESPACE:-ibm-licensing}"

# OpenShift Monitoring Namespace
OM_NAMESPACE="${OM_NAMESPACE:-openshift-monitoring}"

# OpenShift User Workload Monitoring Namespace
OUWM_NAMESPACE="${OUWM_NAMESPACE:-openshift-user-workload-monitoring}"

BASEPATH="${BASEPATH:-ibm-metrics-operator-must-gather}"


IMO_K8S_OBJS="pod serviceaccount persistentvolumeclaim deployment statefulset replicaset cronjob job configmap marketplaceconfig meterbase meterreport razeedeployment route servicemonitor subscription clusterserviceversion"

LS_K8S_OBJS="pod serviceaccount deployment replicaset configmap route servicemonitor"

OM_K8S_OBJS="pod serviceaccount persistentvolumeclaim deployment statefulset replicaset configmap route servicemonitor"


# Check which CLI tool is available

if which oc > /dev/null; then
KCMD=oc
elif which kubectl > /dev/null; then
KCMD=kubectl
else
echo "no oc or kubectl in PATH."
exit
fi

### Functions ###

# $1 BASEPATH
# $2 NAMESPACE
# $3 OBJS
getobjs () {
local BASEPATH="$1"
local NAMESPACE="$2"
local OBJS=("$3")

mkdir -p $BASEPATH/$NAMESPACE

for OBJ in ${OBJS[@]}; do
# Get
$KCMD -n $NAMESPACE get $OBJ > $BASEPATH/$NAMESPACE/$OBJ-get.txt

# Describe
$KCMD -n $NAMESPACE describe $OBJ > $BASEPATH/$NAMESPACE/$OBJ-describe.txt

# Get YAML
$KCMD -n $NAMESPACE get $OBJ -o=yaml > $BASEPATH/$NAMESPACE/$OBJ-get.yaml
done

# Pod Logs
for POD in $($KCMD -n $NAMESPACE get pod --output=jsonpath={.items..metadata.name}); do $KCMD -n $NAMESPACE logs --all-containers=true $POD > $BASEPATH/$NAMESPACE/$POD.log ; done

# Pod Previous Logs
for POD in $($KCMD -n $NAMESPACE get pod --output=jsonpath={.items..metadata.name}); do $KCMD -n $NAMESPACE logs -p --all-containers=true $POD > $BASEPATH/$NAMESPACE/$POD-prev.log ; done
}



### IBM Metrics Operator ###

# Get namespaced object details
getobjs "${BASEPATH}" "${IMO_NAMESPACE}" "${IMO_K8S_OBJS}"

# List namespaced Secrets
$KCMD -n $IMO_NAMESPACE get secret > $BASEPATH/$IMO_NAMESPACE/secret-get.txt

# All MeterDefinitions
$KCMD get meterdefinitions --all-namespaces -o=yaml > $BASEPATH/meterdefinitions-get.yaml

# Prometheus metric-state data
set +x
TOKEN=$($KCMD whoami -t) && \
HOST=$($KCMD -n $OM_NAMESPACE get route thanos-querier -ojsonpath={.spec.host}) && \
curl -H "Authorization: Bearer $TOKEN" -k "https://$HOST/api/v1/query?" --data-urlencode 'query=meterdef_metric_label_info' > $BASEPATH/$IMO_NAMESPACE/prom-metric-state.txt
set -x


### IBM Licensing Service ###

# Get namespaced object details
getobjs "${BASEPATH}" "${LS_NAMESPACE}" "${LS_K8S_OBJS}"

# Prometheus licensing-service product_license_usage data
set +x
TOKEN=$($KCMD whoami -t) && \
HOST=$($KCMD -n $OM_NAMESPACE get route thanos-querier -ojsonpath={.spec.host}) && \
curl -H "Authorization: Bearer $TOKEN" -k "https://$HOST/api/v1/query?" --data-urlencode 'query=avg_over_time(product_license_usage{}[1d])' > $BASEPATH/$LS_NAMESPACE/prom-licensing-service.txt
set -x


### Openshift Monitoring ###

# Get namespaced object details
getobjs "${BASEPATH}" "${OM_NAMESPACE}" "${OM_K8S_OBJS}"

# Active monitoring targets
set +x
TOKEN=$($KCMD whoami -t) && \
HOST=$($KCMD -n $OM_NAMESPACE get route thanos-querier -ojsonpath={.spec.host}) && \
curl -H "Authorization: Bearer $TOKEN" -k "https://$HOST/api/v1/targets?state=active" > $BASEPATH/$OM_NAMESPACE/active-targets.log
set -x

### Openshift User Workload Monitoring ###

# Get namespaced object details
getobjs "${BASEPATH}" "${OUWM_NAMESPACE}" "${OM_K8S_OBJS}"


### Archive ###
tar -czvf $BASEPATH.tar.gz $BASEPATH
6 changes: 5 additions & 1 deletion v2/controllers/marketplace/clusterregistration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (r *ClusterRegistrationReconciler) Reconcile(ctx context.Context, request r
return reconcile.Result{}, err
}

// Ensure Secrets have DeletionTimestamp, relying on GC is a race condition
if err := secretFetcher.DeleteSecret(); err != nil {
return reconcile.Result{}, nil
}

reqLogger.Info("marketplaceconfig delete is complete.")
return reconcile.Result{}, nil

Expand Down Expand Up @@ -505,7 +510,6 @@ func (r *ClusterRegistrationReconciler) SetupWithManager(mgr ctrl.Manager) error
builder.WithPredicates(predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return true },
UpdateFunc: func(e event.UpdateEvent) bool {

marketplaceConfigNew, newOk := e.ObjectNew.(*marketplacev1alpha1.MarketplaceConfig)
marketplaceConfigOld, oldOk := e.ObjectOld.(*marketplacev1alpha1.MarketplaceConfig)

Expand Down
16 changes: 9 additions & 7 deletions v2/controllers/marketplace/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/go-logr/logr"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/redhat-marketplace/redhat-marketplace-operator/v2/pkg/config"
"github.com/redhat-marketplace/redhat-marketplace-operator/v2/pkg/manifests"
utils "github.com/redhat-marketplace/redhat-marketplace-operator/v2/pkg/utils"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -50,6 +51,7 @@ type DeploymentReconciler struct {
Scheme *runtime.Scheme
Log logr.Logger
Factory *manifests.Factory
Cfg *config.OperatorConfig
}

// +kubebuilder:rbac:groups="apps",namespace=system,resources=deployments,verbs=get;list;watch
Expand Down Expand Up @@ -117,7 +119,7 @@ func (r *DeploymentReconciler) SetupWithManager(mgr manager.Manager) error {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: utils.RHM_METERING_DEPLOYMENT_NAME,
Namespace: obj.GetNamespace(),
Namespace: r.Cfg.DeployedNamespace,
}},
}
})
Expand All @@ -139,13 +141,13 @@ func (r *DeploymentReconciler) SetupWithManager(mgr manager.Manager) error {

pConfigMap := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return e.ObjectNew.GetName() == utils.METRICS_OP_CA_BUNDLE_CONFIGMAP
return e.ObjectNew.GetName() == utils.METRICS_OP_CA_BUNDLE_CONFIGMAP && e.ObjectNew.GetNamespace() == r.Cfg.DeployedNamespace
},
CreateFunc: func(e event.CreateEvent) bool {
return e.Object.GetName() == utils.METRICS_OP_CA_BUNDLE_CONFIGMAP
return e.Object.GetName() == utils.METRICS_OP_CA_BUNDLE_CONFIGMAP && e.Object.GetNamespace() == r.Cfg.DeployedNamespace
},
DeleteFunc: func(e event.DeleteEvent) bool {
return e.Object.GetName() == utils.METRICS_OP_CA_BUNDLE_CONFIGMAP
return e.Object.GetName() == utils.METRICS_OP_CA_BUNDLE_CONFIGMAP && e.Object.GetNamespace() == r.Cfg.DeployedNamespace
},
GenericFunc: func(e event.GenericEvent) bool {
return false
Expand All @@ -169,13 +171,13 @@ func (r *DeploymentReconciler) SetupWithManager(mgr manager.Manager) error {

pService := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return e.ObjectNew.GetName() == utils.METRICS_OP_METRICS_SERVICE
return e.ObjectNew.GetName() == utils.METRICS_OP_METRICS_SERVICE && e.ObjectNew.GetNamespace() == r.Cfg.DeployedNamespace
},
CreateFunc: func(e event.CreateEvent) bool {
return e.Object.GetName() == utils.METRICS_OP_METRICS_SERVICE
return e.Object.GetName() == utils.METRICS_OP_METRICS_SERVICE && e.Object.GetNamespace() == r.Cfg.DeployedNamespace
},
DeleteFunc: func(e event.DeleteEvent) bool {
return e.Object.GetName() == utils.METRICS_OP_METRICS_SERVICE
return e.Object.GetName() == utils.METRICS_OP_METRICS_SERVICE && e.Object.GetNamespace() == r.Cfg.DeployedNamespace
},
GenericFunc: func(e event.GenericEvent) bool {
return false
Expand Down
1 change: 1 addition & 0 deletions v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ func main() {
Log: ctrl.Log.WithName("controllers").WithName("DeploymentReconciler"),
Scheme: mgr.GetScheme(),
Factory: factory,
Cfg: opCfg,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DeploymentReconciler")
os.Exit(1)
Expand Down
18 changes: 18 additions & 0 deletions v2/pkg/utils/secretutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
marketplacev1alpha1 "github.com/redhat-marketplace/redhat-marketplace-operator/v2/apis/marketplace/v1alpha1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -123,6 +124,23 @@ func (sf *SecretFetcherBuilder) GetPullSecret() (*v1.Secret, error) {
return rhmPullSecret, nil
}

// Delete Secrets, ignore IsNotFound
func (sf *SecretFetcherBuilder) DeleteSecret() error {
if err := sf.K8sClient.Delete(
sf.Ctx,
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: RHMPullSecretName, Namespace: sf.DeployedNamespace}},
); err != nil && !k8serrors.IsNotFound(err) {
return err
}
if err := sf.K8sClient.Delete(
sf.Ctx,
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: IBMEntitlementKeySecretName, Namespace: sf.DeployedNamespace}},
); err != nil && !k8serrors.IsNotFound(err) {
return err
}
return nil
}

// Parse v1.Secret and return SecretInfo
// Will handle case if ibm-entitlement-key is written into redhat-marketplace-pull-secret
func (sf *SecretFetcherBuilder) Parse(secret *v1.Secret) (*SecretInfo, error) {
Expand Down
4 changes: 2 additions & 2 deletions v2/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

package version

const Version = "2.17.1"
const LastVersion = "2.17.0"
const Version = "2.17.2"
const LastVersion = "2.17.1"

0 comments on commit 7403d50

Please sign in to comment.