Skip to content
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
21 changes: 14 additions & 7 deletions controllers/runtimecomponent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ func (r *RuntimeComponentReconciler) Reconcile(ctx context.Context, req ctrl.Req
return reconcile.Result{}, err
}

isKnativeSupported, err := r.IsGroupVersionSupported(servingv1.SchemeGroupVersion.String(), "Service")
if err != nil {
r.ManageError(err, common.StatusConditionTypeReconciled, instance)
} else if !isKnativeSupported {
reqLogger.V(1).Info(fmt.Sprintf("%s is not supported on the cluster", servingv1.SchemeGroupVersion.String()))
}

// Check if there is an existing Deployment, Statefulset or Knative service by this name
// not managed by this operator
err = appstacksutils.CheckForNameConflicts("RuntimeComponent", instance.Name, instance.Namespace, r.GetClient(), req, isKnativeSupported)
if err != nil {
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
}

// initialize the RuntimeComponent instance
instance.Initialize()
_, err = appstacksutils.Validate(instance)
Expand Down Expand Up @@ -227,13 +241,6 @@ func (r *RuntimeComponentReconciler) Reconcile(ctx context.Context, req ctrl.Req
return r.ManageError(saErr, common.StatusConditionTypeReconciled, instance)
}

isKnativeSupported, err := r.IsGroupVersionSupported(servingv1.SchemeGroupVersion.String(), "Service")
if err != nil {
r.ManageError(err, common.StatusConditionTypeReconciled, instance)
} else if !isKnativeSupported {
reqLogger.V(1).Info(fmt.Sprintf("%s is not supported on the cluster", servingv1.SchemeGroupVersion.String()))
}

if instance.Spec.CreateKnativeService != nil && *instance.Spec.CreateKnativeService {
// Clean up non-Knative resources
resources := []client.Object{
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bundle() {
echo "------------"
echo "bundle-push"
echo "------------"
make -C $MAKEFILE_DIR bundle-push PUBLISH_REGISTRY=$OCP_REGISTRY_URL BUNDLE_IMG=$NAMESPACE/$OPERATOR_NAME-bundle:$VVERSION TLS_VERIFY=false
make -C $MAKEFILE_DIR bundle-push VERSION=$VVERSION IMG=$IMG IMAGE_TAG_BASE=$IMAGE_TAG_BASE BUNDLE_IMG=$BUNDLE_IMG CATALOG_IMG=$CATALOG_IMG TLS_VERIFY=false
}

###################################
Expand Down
47 changes: 47 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var APIVersionNotFoundError = errors.New("APIVersion is not available")
Expand Down Expand Up @@ -1570,3 +1571,49 @@ func GetIssuerResourceVersion(client client.Client, certificate *certmanagerv1.C
return issuer.ResourceVersion, nil
}
}

func CheckForNameConflicts(operator string, name string, namespace string, client client.Client, request reconcile.Request, isKnativeSupported bool) error {
defaultMeta := metav1.ObjectMeta{
Name: name,
Namespace: namespace,
}
// Check to see if the knative service is owned by us
if isKnativeSupported {
ksvc := &servingv1.Service{ObjectMeta: defaultMeta}
err := client.Get(context.TODO(), request.NamespacedName, ksvc)
if err == nil {
for _, element := range ksvc.OwnerReferences {
if element.Kind != operator {
message := "Existing Knative Service \"" + name + "\" is not managed by this operator. It is being managed by \"" + element.Kind + "\". Resolve the naming conflict."
err = errors.New(message)
return err
}
}
}
}
// Check to see if the existing deployment or statefulsets are owned by us
deploy := &appsv1.Deployment{ObjectMeta: defaultMeta}
err := client.Get(context.TODO(), request.NamespacedName, deploy)
if err == nil {
for _, element := range deploy.OwnerReferences {
if element.Kind != operator {
message := "Existing Deployment \"" + name + "\" is not managed by this operator. It is being managed by \"" + element.Kind + "\". Resolve the naming conflict."
err = errors.New(message)
return err
}
}
}
// Check to see if the existing statefulset is owned by us
statefulSet := &appsv1.StatefulSet{ObjectMeta: defaultMeta}
err = client.Get(context.TODO(), request.NamespacedName, statefulSet)
if err == nil {
for _, element := range statefulSet.OwnerReferences {
if element.Kind != operator {
message := "Existing StatefulSet \"" + name + "\" is not managed by this operator. It is being managed by \"" + element.Kind + "\". Resolve the naming conflict."
err = errors.New(message)
return err
}
}
}
return nil
}