Skip to content

Commit

Permalink
Added v1alpha1 back with a warning to use the new apiGroup
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling committed Mar 5, 2019
1 parent 785daf1 commit c332e90
Show file tree
Hide file tree
Showing 15 changed files with 1,115 additions and 0 deletions.
5 changes: 5 additions & 0 deletions deploy/crds/io_v1alpha1_jaeger_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# see /examples
apiVersion: io.jaegertracing/v1alpha1
kind: Jaeger
metadata:
name: example-jaeger
13 changes: 13 additions & 0 deletions deploy/crds/io_v1alpha1_jaeger_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: jaegers.io.jaegertracing
spec:
group: io.jaegertracing
names:
kind: Jaeger
listKind: JaegerList
plural: jaegers
singular: jaeger
scope: Namespaced
version: v1alpha1
10 changes: 10 additions & 0 deletions pkg/apis/addtoscheme_io_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package apis

import (
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
}
12 changes: 12 additions & 0 deletions pkg/apis/io/v1alpha1/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// NewJaeger returns a new Jaeger instance with the given name
func NewJaeger(name string) *Jaeger {
return &Jaeger{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
}
4 changes: 4 additions & 0 deletions pkg/apis/io/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1alpha1 contains API Schema definitions for the io v1alpha1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=io.jaegertracing
package v1alpha1
40 changes: 40 additions & 0 deletions pkg/apis/io/v1alpha1/freeform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v1alpha1

import (
"encoding/json"
)

// FreeForm defines a common options parameter that maintains the hierarchical
// structure of the data, unlike Options which flattens the hierarchy into a
// key/value map where the hierarchy is converted to '.' separated items in the key.
type FreeForm struct {
json []byte
}

// NewFreeForm build a new FreeForm object based on the given map
func NewFreeForm(o map[string]interface{}) FreeForm {
freeForm := FreeForm{}
if o != nil {
freeForm.json, _ = json.Marshal(o)
}
return freeForm
}

// UnmarshalJSON implements an alternative parser for this field
func (o *FreeForm) UnmarshalJSON(b []byte) error {
o.json = b
return nil
}

// MarshalJSON specifies how to convert this object into JSON
func (o FreeForm) MarshalJSON() ([]byte, error) {
if len(o.json) == 0 {
return []byte("{}"), nil
}
return o.json, nil
}

// IsEmpty determines if the freeform options are empty
func (o FreeForm) IsEmpty() bool {
return len(o.json) == 0 || string(o.json) == "{}"
}
53 changes: 53 additions & 0 deletions pkg/apis/io/v1alpha1/freeform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestFreeForm(t *testing.T) {
uiconfig := `{"es":{"password":"changeme","server-urls":"http://elasticsearch:9200","username":"elastic"}}`
o := NewFreeForm(map[string]interface{}{
"es": map[string]interface{}{
"server-urls": "http://elasticsearch:9200",
"username": "elastic",
"password": "changeme",
},
})
json, err := o.MarshalJSON()
assert.NoError(t, err)
assert.NotNil(t, json)
assert.Equal(t, uiconfig, string(o.json))
}

func TestFreeFormUnmarhalMarshal(t *testing.T) {
uiconfig := `{"es":{"password":"changeme","server-urls":"http://elasticsearch:9200","username":"elastic"}}`
o := NewFreeForm(nil)
o.UnmarshalJSON([]byte(uiconfig))
json, err := o.MarshalJSON()
assert.NoError(t, err)
assert.NotNil(t, json)
assert.Equal(t, uiconfig, string(o.json))
}

func TestFreeFormIsEmptyFalse(t *testing.T) {
o := NewFreeForm(map[string]interface{}{
"es": map[string]interface{}{
"server-urls": "http://elasticsearch:9200",
"username": "elastic",
"password": "changeme",
},
})
assert.False(t, o.IsEmpty())
}

func TestFreeFormIsEmptyTrue(t *testing.T) {
o := NewFreeForm(map[string]interface{}{})
assert.True(t, o.IsEmpty())
}

func TestFreeFormIsEmptyNilTrue(t *testing.T) {
o := NewFreeForm(nil)
assert.True(t, o.IsEmpty())
}
202 changes: 202 additions & 0 deletions pkg/apis/io/v1alpha1/jaeger_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package v1alpha1

import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1"
esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1"
)

// IngressSecurityType represents the possible values for the security type
type IngressSecurityType string

const (
// FlagPlatformKubernetes represents the value for the 'platform' flag for Kubernetes
FlagPlatformKubernetes = "kubernetes"

// FlagPlatformOpenShift represents the value for the 'platform' flag for OpenShift
FlagPlatformOpenShift = "openshift"

// FlagPlatformAutoDetect represents the "auto-detect" value for the platform flag
FlagPlatformAutoDetect = "auto-detect"

// FlagProvisionElasticsearchAuto represents the 'auto' value for the 'es-provision' flag
FlagProvisionElasticsearchAuto = "auto"

// FlagProvisionElasticsearchTrue represents the value 'true' for the 'es-provision' flag
FlagProvisionElasticsearchTrue = "true"

// FlagProvisionElasticsearchFalse represents the value 'false' for the 'es-provision' flag
FlagProvisionElasticsearchFalse = "false"

// IngressSecurityNone disables any form of security for ingress objects (default)
IngressSecurityNone IngressSecurityType = ""

// IngressSecurityNoneExplicit used when the user specifically set it to 'none'
IngressSecurityNoneExplicit IngressSecurityType = "none"

// IngressSecurityOAuthProxy represents an OAuth Proxy as security type
IngressSecurityOAuthProxy IngressSecurityType = "oauth-proxy"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// JaegerList is a list of Jaeger structs
type JaegerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Jaeger `json:"items"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Jaeger defines the main structure for the custom-resource
type Jaeger struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec JaegerSpec `json:"spec"`
Status JaegerStatus `json:"status,omitempty"`
}

// JaegerSpec defines the structure of the Jaeger JSON object from the CR
type JaegerSpec struct {
Strategy string `json:"strategy"`
AllInOne JaegerAllInOneSpec `json:"allInOne"`
Query JaegerQuerySpec `json:"query"`
Collector JaegerCollectorSpec `json:"collector"`
Ingester JaegerIngesterSpec `json:"ingester"`
Agent JaegerAgentSpec `json:"agent"`
UI JaegerUISpec `json:"ui"`
Sampling JaegerSamplingSpec `json:"sampling"`
Storage JaegerStorageSpec `json:"storage"`
Ingress JaegerIngressSpec `json:"ingress"`
JaegerCommonSpec
}

// JaegerCommonSpec defines the common elements used in multiple other spec structs
type JaegerCommonSpec struct {
Volumes []v1.Volume `json:"volumes"`
VolumeMounts []v1.VolumeMount `json:"volumeMounts"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

// JaegerStatus defines what is to be returned from a status query
type JaegerStatus struct {
// CollectorSpansReceived represents sum of the metric jaeger_collector_spans_received_total across all collectors
CollectorSpansReceived int `json:"collectorSpansReceived"`

// CollectorSpansDropped represents sum of the metric jaeger_collector_spans_dropped_total across all collectors
CollectorSpansDropped int `json:"collectorSpansDropped"`
}

// JaegerQuerySpec defines the options to be used when deploying the query
type JaegerQuerySpec struct {
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
JaegerCommonSpec
}

// JaegerUISpec defines the options to be used to configure the UI
type JaegerUISpec struct {
Options FreeForm `json:"options"`
}

// JaegerSamplingSpec defines the options to be used to configure the UI
type JaegerSamplingSpec struct {
Options FreeForm `json:"options"`
}

// JaegerIngressSpec defines the options to be used when deploying the query ingress
type JaegerIngressSpec struct {
Enabled *bool `json:"enabled"`
Security IngressSecurityType `json:"security"`
JaegerCommonSpec
}

// JaegerAllInOneSpec defines the options to be used when deploying the query
type JaegerAllInOneSpec struct {
Image string `json:"image"`
Options Options `json:"options"`
JaegerCommonSpec
}

// JaegerCollectorSpec defines the options to be used when deploying the collector
type JaegerCollectorSpec struct {
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
JaegerCommonSpec
}

// JaegerIngesterSpec defines the options to be used when deploying the ingester
type JaegerIngesterSpec struct {
Size int `json:"size"`
Image string `json:"image"`
Options Options `json:"options"`
JaegerCommonSpec
}

// JaegerAgentSpec defines the options to be used when deploying the agent
type JaegerAgentSpec struct {
Strategy string `json:"strategy"` // can be either 'DaemonSet' or 'Sidecar' (default)
Image string `json:"image"`
Options Options `json:"options"`
JaegerCommonSpec
}

// JaegerStorageSpec defines the common storage options to be used for the query and collector
type JaegerStorageSpec struct {
Type string `json:"type"` // can be `memory` (default), `cassandra`, `elasticsearch`, `kafka` or `managed`
SecretName string `json:"secretName"`
Options Options `json:"options"`
CassandraCreateSchema JaegerCassandraCreateSchemaSpec `json:"cassandraCreateSchema"`
SparkDependencies JaegerDependenciesSpec `json:"dependencies"`
EsIndexCleaner JaegerEsIndexCleanerSpec `json:"esIndexCleaner"`
Elasticsearch ElasticsearchSpec `json:"elasticsearch"`
}

// ElasticsearchSpec represents the ES configuration options that we pass down to the Elasticsearch operator
type ElasticsearchSpec struct {
Resources v1.ResourceRequirements `json:"resources"`
NodeCount int32 `json:"nodeCount"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Storage esv1alpha1.ElasticsearchStorageSpec `json:"storage"`
RedundancyPolicy v1alpha1.RedundancyPolicyType `json:"redundancyPolicy"`
}

// JaegerCassandraCreateSchemaSpec holds the options related to the create-schema batch job
type JaegerCassandraCreateSchemaSpec struct {
Enabled *bool `json:"enabled"`
Image string `json:"image"`
Datacenter string `json:"datacenter"`
Mode string `json:"mode"`
}

// JaegerDependenciesSpec defined options for running spark-dependencies.
type JaegerDependenciesSpec struct {
Enabled *bool `json:"enabled"`
SparkMaster string `json:"sparkMaster"`
Schedule string `json:"schedule"`
Image string `json:"image"`
JavaOpts string `json:"javaOpts"`
CassandraUseSsl bool `json:"cassandraUseSsl"`
CassandraLocalDc string `json:"cassandraLocalDc"`
CassandraClientAuthEnabled bool `json:"cassandraClientAuthEnabled"`
ElasticsearchClientNodeOnly bool `json:"elasticsearchClientNodeOnly"`
ElasticsearchNodesWanOnly bool `json:"elasticsearchNodesWanOnly"`
}

// JaegerEsIndexCleanerSpec holds the options related to es-index-cleaner
type JaegerEsIndexCleanerSpec struct {
Enabled *bool `json:"enabled"`
NumberOfDays int `json:"numberOfDays"`
Schedule string `json:"schedule"`
Image string `json:"image"`
}

func init() {
SchemeBuilder.Register(&Jaeger{}, &JaegerList{})
}
11 changes: 11 additions & 0 deletions pkg/apis/io/v1alpha1/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1alpha1

import log "github.com/sirupsen/logrus"

// Logger returns a logger filled with context-related fields, such as Name and Namespace
func (j *Jaeger) Logger() *log.Entry {
return log.WithFields(log.Fields{
"instance": j.Name,
"namespace": j.Namespace,
})
}
Loading

0 comments on commit c332e90

Please sign in to comment.