Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package operator_test | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/appscode/go/log" | ||
prom_util "github.com/appscode/kube-mon/prometheus/v1" | ||
"github.com/appscode/kutil/discovery" | ||
searchlight_api "github.com/appscode/searchlight/apis/monitoring/v1alpha1" | ||
stash_api "github.com/appscode/stash/apis/stash/v1alpha1" | ||
voyager_api "github.com/appscode/voyager/apis/voyager/v1beta1" | ||
prom "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1" | ||
kubedb_api "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1" | ||
core "k8s.io/api/core/v1" | ||
storage_v1 "k8s.io/api/storage/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/kubernetes" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/util/homedir" | ||
// admission "k8s.io/api/admission/v1beta1" | ||
// admissionregistration "k8s.io/api/admissionregistration/v1beta1" | ||
apps "k8s.io/api/apps/v1" | ||
// authentication "k8s.io/api/authentication/v1" | ||
// authorization "k8s.io/api/authorization/v1" | ||
autoscaling "k8s.io/api/autoscaling/v1" | ||
batch_v1 "k8s.io/api/batch/v1" | ||
batch_v1beta1 "k8s.io/api/batch/v1beta1" | ||
certificates "k8s.io/api/certificates/v1beta1" | ||
// events "k8s.io/api/events/v1beta1" | ||
extensions "k8s.io/api/extensions/v1beta1" | ||
// imagepolicy "k8s.io/api/imagepolicy/v1alpha1" | ||
networking "k8s.io/api/networking/v1" | ||
policy "k8s.io/api/policy/v1beta1" | ||
rbac "k8s.io/api/rbac/v1" | ||
// scheduling "k8s.io/api/scheduling/v1alpha1" | ||
settings "k8s.io/api/settings/v1alpha1" | ||
) | ||
|
||
func TestRestMapper(t *testing.T) { | ||
masterURL := "" | ||
kubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube/config") | ||
|
||
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath) | ||
if err != nil { | ||
log.Fatalf("Could not get Kubernetes config: %s", err) | ||
} | ||
|
||
kc := kubernetes.NewForConfigOrDie(config) | ||
|
||
restmapper, err := discovery.LoadRestMapper(kc.Discovery()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
data := []struct { | ||
in interface{} | ||
out schema.GroupVersionResource | ||
}{ | ||
{&apps.ControllerRevision{}, apps.SchemeGroupVersion.WithResource("controllerrevisions")}, | ||
{&apps.Deployment{}, apps.SchemeGroupVersion.WithResource("deployments")}, | ||
{&apps.ReplicaSet{}, apps.SchemeGroupVersion.WithResource("replicasets")}, | ||
{&apps.StatefulSet{}, apps.SchemeGroupVersion.WithResource("statefulsets")}, | ||
{&autoscaling.HorizontalPodAutoscaler{}, autoscaling.SchemeGroupVersion.WithResource("horizontalpodautoscalers")}, | ||
{&batch_v1.Job{}, batch_v1.SchemeGroupVersion.WithResource("jobs")}, | ||
{&batch_v1beta1.CronJob{}, batch_v1beta1.SchemeGroupVersion.WithResource("cronjobs")}, | ||
{&certificates.CertificateSigningRequest{}, certificates.SchemeGroupVersion.WithResource("certificatesigningrequests")}, | ||
{&core.ComponentStatus{}, core.SchemeGroupVersion.WithResource("componentstatuses")}, | ||
{&core.ConfigMap{}, core.SchemeGroupVersion.WithResource("configmaps")}, | ||
{&core.Endpoints{}, core.SchemeGroupVersion.WithResource("endpoints")}, | ||
{&core.Event{}, core.SchemeGroupVersion.WithResource("events")}, | ||
{&core.LimitRange{}, core.SchemeGroupVersion.WithResource("limitranges")}, | ||
{&core.Namespace{}, core.SchemeGroupVersion.WithResource("namespaces")}, | ||
{&core.Node{}, core.SchemeGroupVersion.WithResource("nodes")}, | ||
{&core.PersistentVolumeClaim{}, core.SchemeGroupVersion.WithResource("persistentvolumeclaims")}, | ||
{&core.PersistentVolume{}, core.SchemeGroupVersion.WithResource("persistentvolumes")}, | ||
{&core.PodTemplate{}, core.SchemeGroupVersion.WithResource("podtemplates")}, | ||
{&core.Pod{}, core.SchemeGroupVersion.WithResource("pods")}, | ||
{&core.ReplicationController{}, core.SchemeGroupVersion.WithResource("replicationcontrollers")}, | ||
{&core.ResourceQuota{}, core.SchemeGroupVersion.WithResource("resourcequotas")}, | ||
{&core.Secret{}, core.SchemeGroupVersion.WithResource("secrets")}, | ||
{&core.ServiceAccount{}, core.SchemeGroupVersion.WithResource("serviceaccounts")}, | ||
{&core.Service{}, core.SchemeGroupVersion.WithResource("services")}, | ||
{&extensions.DaemonSet{}, extensions.SchemeGroupVersion.WithResource("daemonsets")}, | ||
{&extensions.Ingress{}, extensions.SchemeGroupVersion.WithResource("ingresses")}, | ||
{&networking.NetworkPolicy{}, networking.SchemeGroupVersion.WithResource("networkpolicies")}, | ||
{&policy.PodDisruptionBudget{}, policy.SchemeGroupVersion.WithResource("poddisruptionbudgets")}, | ||
{&rbac.ClusterRoleBinding{}, rbac.SchemeGroupVersion.WithResource("clusterrolebindings")}, | ||
{&rbac.ClusterRole{}, rbac.SchemeGroupVersion.WithResource("clusterroles")}, | ||
{&rbac.RoleBinding{}, rbac.SchemeGroupVersion.WithResource("rolebindings")}, | ||
{&rbac.Role{}, rbac.SchemeGroupVersion.WithResource("roles")}, | ||
{&settings.PodPreset{}, settings.SchemeGroupVersion.WithResource("podpresets")}, | ||
{&storage_v1.StorageClass{}, storage_v1.SchemeGroupVersion.WithResource("storageclasses")}, | ||
|
||
// voyager | ||
{&voyager_api.Ingress{}, voyager_api.SchemeGroupVersion.WithResource(voyager_api.ResourceTypeIngress)}, | ||
{&voyager_api.Certificate{}, voyager_api.SchemeGroupVersion.WithResource(voyager_api.ResourceTypeCertificate)}, | ||
|
||
// stash | ||
{&stash_api.Restic{}, stash_api.SchemeGroupVersion.WithResource(stash_api.ResourceTypeRestic)}, | ||
{&stash_api.Recovery{}, stash_api.SchemeGroupVersion.WithResource(stash_api.ResourceTypeRecovery)}, | ||
|
||
// searchlight | ||
{&searchlight_api.ClusterAlert{}, searchlight_api.SchemeGroupVersion.WithResource(searchlight_api.ResourceTypeClusterAlert)}, | ||
{&searchlight_api.NodeAlert{}, searchlight_api.SchemeGroupVersion.WithResource(searchlight_api.ResourceTypeNodeAlert)}, | ||
{&searchlight_api.PodAlert{}, searchlight_api.SchemeGroupVersion.WithResource(searchlight_api.ResourceTypePodAlert)}, | ||
|
||
// kubedb | ||
{&kubedb_api.Postgres{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypePostgres)}, | ||
{&kubedb_api.Elasticsearch{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeElasticsearch)}, | ||
{&kubedb_api.MySQL{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeMySQL)}, | ||
{&kubedb_api.MongoDB{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeMongoDB)}, | ||
{&kubedb_api.Redis{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeRedis)}, | ||
{&kubedb_api.Memcached{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeMemcached)}, | ||
{&kubedb_api.Snapshot{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeSnapshot)}, | ||
{&kubedb_api.DormantDatabase{}, kubedb_api.SchemeGroupVersion.WithResource(kubedb_api.ResourceTypeDormantDatabase)}, | ||
|
||
// coreos-prometheus | ||
{&prom.Prometheus{}, prom_util.SchemeGroupVersion.WithResource(prom.PrometheusesKind)}, | ||
{&prom.ServiceMonitor{}, prom_util.SchemeGroupVersion.WithResource(prom.ServiceMonitorsKind)}, | ||
{&prom.Alertmanager{}, prom_util.SchemeGroupVersion.WithResource(prom.AlertmanagersKind)}, | ||
} | ||
|
||
for _, tt := range data { | ||
gvr, err := discovery.DetectResource(restmapper, tt.in) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if gvr != tt.out { | ||
t.Errorf("Failed to DetectResource: expected %+v, got %+v", tt.out, gvr) | ||
} | ||
} | ||
} |