Skip to content
generated.go 3.18 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
package ingress

import (
	"fmt"

	"github.com/ankitrgadiya/operatorlib/pkg/interfaces"
	corev1 "k8s.io/api/core/v1"
	networkingv1beta1 "k8s.io/api/networking/v1beta1"
Timothee Gosselin's avatar
Timothee Gosselin committed
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/client-go/tools/record"
	"sigs.k8s.io/controller-runtime/pkg/client"
)

func (c Conf) GenIngressBackend() (out *networkingv1beta1.IngressBackend, err error) {
	if c.GenIngressBackendFunc != nil {
		return c.GenIngressBackendFunc()
	}
	return out, nil
}
func (c Conf) GenIngressTLS() (out []networkingv1beta1.IngressTLS, err error) {
	if c.GenIngressTLSFunc != nil {
		return c.GenIngressTLSFunc()
	}
	return out, nil
}
func (c Conf) GenIngressRules() (out []networkingv1beta1.IngressRule, err error) {
	if c.GenIngressRulesFunc != nil {
		return c.GenIngressRulesFunc()
	}
	return out, nil
}

Timothee Gosselin's avatar
Timothee Gosselin committed
func (c Conf) GenLabelsFunc() (map[string]string, error) {
	var labels map[string]string
	if c.GenLabels != nil {
		return c.GenLabels()
	}
	return labels, nil
}
func (c Conf) GenAnnotationsFunc() (map[string]string, error) {
	var annotations map[string]string
	if c.GenAnnotations != nil {
		return c.GenAnnotations()
	}
	return annotations, nil

}
func (c Conf) GenFinalizersFunc() ([]string, error) {
	if c.GenFinalizers != nil {
		return c.GenFinalizers()
	}
	return nil, nil

}

// Object returns the ObjectSyncer subject
func (s Conf) Object() interfaces.Object {
	return s.Obj
}

// Object returns the ObjectSyncer subject
func (s Conf) ObjectName() string {
	return s.Name
}

// Object returns the ObjectSyncer subject
func (s Conf) ObjectNamespace() string {
	return s.Namespace
}

// ObjectOwner returns the ObjectSyncer owner
func (s Conf) ObjectOwner() interfaces.Object {
	return s.Owner
}

// ObjectWithoutSecretData returns the ObjectSyncer subject without secret data
func (s Conf) ObjectWithoutSecretData() runtime.Object {
	return stripSecrets(s.Obj)
}

// PreviousWithoutSecretData returns the ObjectSyncer previous subject without secret data
func (s Conf) PreviousWithoutSecretData() runtime.Object {
	return stripSecrets(s.previousObject)
}

// ObjectType returns the type of the ObjectSyncer subject
func (s Conf) ObjectType() string {
	return fmt.Sprintf("%T", s.Obj)
}

// OwnerType returns the type of the ObjectSyncer owner
func (s Conf) ObjectOwnerType() string {
	return fmt.Sprintf("%T", s.Owner)
}

// OwnerType returns the type of the ObjectSyncer owner
func (s Conf) SetPreviousObject() {
	//	obj := s.Obj.DeepCopyObject().(*appsv1.Deployment)
	//	s.previousObject = obj
	s.previousObject = s.Object()
	//s.previousObject = s.Object()
	return
}

// OwnerType returns the type of the ObjectSyncer owner
func (s Conf) GetClient() client.Client {
	return s.Reconcile.GetClient()
}

// OwnerType returns the type of the ObjectSyncer owner
func (s Conf) GetScheme() *runtime.Scheme {
	return s.Reconcile.GetScheme()
}

// OwnerType returns the type of the ObjectSyncer owner
func (s Conf) GetRecorder() record.EventRecorder {
	return s.Reconcile.GetRecorder()
}

// stripSecrets returns the object without secretData
func stripSecrets(obj runtime.Object) runtime.Object {
	// if obj is secret, don't print secret data
	s, ok := obj.(*corev1.Secret)
	if ok {
		s.Data = nil
		s.StringData = nil

		return s
	}

	return obj
}