Skip to content

Commit

Permalink
Remove TypeMeta declaration from the implementation of the objects
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed May 22, 2019
1 parent a67086a commit a57e1d5
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Removed

### Bug Fixes
- Remove TypeMeta declaration from the implementation of the objects

- Fixes a regression that causes Helm RBAC generation to contain an empty custom ruleset when the chart's default manifest contains only namespaced resources. ([#1456](https://github.com/operator-framework/operator-sdk/pull/1456))
- Fixes an issue that causes Helm RBAC generation to fail when creating new operators with a Kubernetes context configured to connect to an OpenShift cluster. ([#1461](https://github.com/operator-framework/operator-sdk/pull/1461))
Expand Down
4 changes: 0 additions & 4 deletions doc/design/milestone-0.0.2/action-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ import (
func Handle(ctx context.Context, event sdkType.Event) {
...
pod := &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta {
Name: "example",
Namespace: "default",
Expand Down
11 changes: 1 addition & 10 deletions doc/design/milestone-0.0.2/query-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ Example Usage:
// meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

d := &apps_v1.Deployment{
TypeMeta: meta_v1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
}
ObjectMeta: meta_v1.ObjectMeta{
Name: "example",
Namespace: "default",
Expand Down Expand Up @@ -81,12 +77,7 @@ Example usage:
// meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// apps_v1 "k8s.io/api/apps/v1"

dl := &apps_v1.DeploymentList{
TypeMeta: meta_v1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
}
}
dl := &apps_v1.DeploymentList{}
// List with default options
err = sdk.List("default", dl)
// List with custom options
Expand Down
11 changes: 1 addition & 10 deletions doc/test-framework/writing-e2e-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ To do this, pass the CRD's `AddToScheme` function and its List type object to th
[AddToFrameworkScheme][scheme-link] function. For our example memcached-operator, it looks like this:

```go
memcachedList := &cachev1alpha1.MemcachedList{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
}
memcachedList := &cachev1alpha1.MemcachedList{}
err := framework.AddToFrameworkScheme(apis.AddToScheme, memcachedList)
if err != nil {
t.Fatalf("failed to add custom resource scheme to framework: %v", err)
Expand Down Expand Up @@ -168,10 +163,6 @@ This is how we can create a custom memcached custom resource with a size of 3:
```go
// create memcached custom resource
exampleMemcached := &cachev1alpha1.Memcached{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "example-memcached",
Namespace: namespace,
Expand Down
4 changes: 0 additions & 4 deletions doc/user/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,6 @@ func (r *ReconcileKind) deploymentForApp(m *appv1alpha1.App) *appsv1.Deployment
replicas := m.Spec.Size

dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: m.Name,
Namespace: m.Namespace,
Expand Down
4 changes: 0 additions & 4 deletions example/memcached-operator/memcached_controller.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ func (r *ReconcileMemcached) deploymentForMemcached(m *cachev1alpha1.Memcached)
replicas := m.Spec.Size

dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: m.Name,
Namespace: m.Namespace,
Expand Down
4 changes: 0 additions & 4 deletions internal/pkg/scaffold/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ func (s *CRD) CustomRender() ([]byte, error) {

func newCRDForResource(r *Resource) *apiextv1beta1.CustomResourceDefinition {
crd := &apiextv1beta1.CustomResourceDefinition{
TypeMeta: metav1.TypeMeta{
APIVersion: "apiextensions.k8s.io/v1beta1",
Kind: "CustomResourceDefinition",
},
ObjectMeta: metav1.ObjectMeta{
Name: r.Resource + "." + r.FullGroup,
},
Expand Down
4 changes: 0 additions & 4 deletions internal/pkg/scorecard/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ func UpdateSuiteStates(suite scapiv1alpha1.ScorecardSuiteResult) scapiv1alpha1.S

func CombineScorecardOutput(outputs []scapiv1alpha1.ScorecardOutput, log string) scapiv1alpha1.ScorecardOutput {
output := scapiv1alpha1.ScorecardOutput{
TypeMeta: metav1.TypeMeta{
Kind: "ScorecardOutput",
APIVersion: "osdk.openshift.io/v1alpha1",
},
Log: log,
}
for _, item := range outputs {
Expand Down
11 changes: 1 addition & 10 deletions pkg/leader/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ func Become(ctx context.Context, lockName string) error {
}

// check for existing lock from this pod, in case we got restarted
existing := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
}
existing := &corev1.ConfigMap{}
key := crclient.ObjectKey{Namespace: ns, Name: lockName}
err = client.Get(ctx, key, existing)

Expand All @@ -98,10 +93,6 @@ func Become(ctx context.Context, lockName string) error {
}

cm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: lockName,
Namespace: ns,
Expand Down
4 changes: 0 additions & 4 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ func initOperatorService(ctx context.Context, client crclient.Client, port int32
Namespace: namespace,
Labels: label,
},
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
{
Expand Down
4 changes: 0 additions & 4 deletions pkg/metrics/service-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ func GenerateServiceMonitor(s *v1.Service) *monitoringv1.ServiceMonitor {
}

return &monitoringv1.ServiceMonitor{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceMonitor",
APIVersion: "monitoring.coreos.com/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: s.ObjectMeta.Name,
Namespace: s.ObjectMeta.Namespace,
Expand Down
7 changes: 1 addition & 6 deletions pkg/test/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ type addToSchemeFunc func(*runtime.Scheme) error
// the addToScheme function (located in the register.go file of their operator
// project) and the List struct for their custom resource. For example, for a
// memcached operator, the list stuct may look like:
// &MemcachedList{
// TypeMeta: metav1.TypeMeta{
// Kind: "Memcached",
// APIVersion: "cache.example.com/v1alpha1",
// },
// }
// &MemcachedList{}
// The List object is needed because the CRD has not always been fully registered
// by the time this function is called. If the CRD takes more than 5 seconds to
// become ready, this function throws an error
Expand Down
11 changes: 1 addition & 10 deletions test/e2e/incluster-test-code/memcached_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ var (
)

func TestMemcached(t *testing.T) {
memcachedList := &operator.MemcachedList{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
}
memcachedList := &operator.MemcachedList{}
err := framework.AddToFrameworkScheme(apis.AddToScheme, memcachedList)
if err != nil {
t.Fatalf("Failed to add custom resource scheme to framework: %v", err)
Expand All @@ -61,10 +56,6 @@ func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.Tes
}
// create memcached custom resource
exampleMemcached := &operator.Memcached{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "example-memcached",
Namespace: namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ func (r *ReconcileMemcachedRS) replicaSetForMemcached(m *cachev1alpha1.Memcached
replicas := m.Spec.NumNodes

replicaSet := &appsv1.ReplicaSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "ReplicaSet",
},
ObjectMeta: metav1.ObjectMeta{
Name: m.Name,
Namespace: m.Namespace,
Expand Down
11 changes: 1 addition & 10 deletions test/test-framework/test/e2e/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ const (
)

func TestMemcached(t *testing.T) {
memcachedList := &operator.MemcachedList{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
}
memcachedList := &operator.MemcachedList{}
err := framework.AddToFrameworkScheme(apis.AddToScheme, memcachedList)
if err != nil {
t.Fatalf("Failed to add custom resource scheme to framework: %v", err)
Expand All @@ -61,10 +56,6 @@ func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.Tes
}
// create memcached custom resource
exampleMemcached := &operator.Memcached{
TypeMeta: metav1.TypeMeta{
Kind: "Memcached",
APIVersion: "cache.example.com/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "example-memcached",
Namespace: namespace,
Expand Down

0 comments on commit a57e1d5

Please sign in to comment.