Skip to content

Commit

Permalink
Merge pull request #150 from castai/dd-eds-crd
Browse files Browse the repository at this point in the history
Process DataDog ExtendedDaemonSetReplicaSet CRDs
  • Loading branch information
kiriloman authored Dec 18, 2023
2 parents cedc892 + d6dca5e commit 50bf5ac
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
cloud.google.com/go/compute/metadata v0.2.3
github.com/DataDog/extendeddaemonset v0.9.0-rc.3
github.com/aws/aws-sdk-go v1.44.294
github.com/aws/karpenter v0.29.2
github.com/aws/karpenter-core v0.29.2
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/extendeddaemonset v0.9.0-rc.3 h1:jlf40dnVG069YsjU4SfV3UUvgFdFhMfyyyFzsTyd/fk=
github.com/DataDog/extendeddaemonset v0.9.0-rc.3/go.mod h1:ZuADIM2ye3GSLokHyPi/BGhyhvHSCjvDHU3BPXHr8Ow=
github.com/Pallinder/go-randomdata v1.2.0 h1:DZ41wBchNRb/0GfsePLiSwb0PHZmT67XY00lCDlaYPg=
github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y=
github.com/aws/aws-sdk-go v1.44.294 h1:3x7GaEth+pDU9HwFcAU0awZlEix5CEdyIZvV08SlHa8=
Expand Down Expand Up @@ -217,6 +219,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
Expand Down
9 changes: 9 additions & 0 deletions internal/services/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

datadoghqv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1"
karpenterCore "github.com/aws/karpenter-core/pkg/apis/v1alpha5"
karpenter "github.com/aws/karpenter/pkg/apis/v1alpha1"
"github.com/samber/lo"
Expand Down Expand Up @@ -505,6 +506,14 @@ func getConditionalInformers(f informers.SharedInformerFactory, df dynamicinform
return df.ForResource(karpenter.SchemeGroupVersion.WithResource("awsnodetemplates")).Informer()
},
},
{
resource: datadoghqv1alpha1.GroupVersion.WithResource("extendeddaemonsetreplicasets"),
apiType: reflect.TypeOf(&datadoghqv1alpha1.ExtendedDaemonSetReplicaSet{}),
permissionVerbs: []string{"get", "list", "watch"},
informerFactory: func() cache.SharedIndexInformer {
return df.ForResource(datadoghqv1alpha1.GroupVersion.WithResource("extendeddaemonsetreplicasets")).Informer()
},
},
{
resource: v1beta1.SchemeGroupVersion.WithResource("pods"),
apiType: reflect.TypeOf(&v1beta1.PodMetrics{}),
Expand Down
33 changes: 31 additions & 2 deletions internal/services/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

datadoghqv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1"
karpenterCore "github.com/aws/karpenter-core/pkg/apis/v1alpha5"
karpenter "github.com/aws/karpenter/pkg/apis/v1alpha1"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -64,6 +65,7 @@ func TestController_HappyPath(t *testing.T) {
scheme := runtime.NewScheme()
utilruntime.Must(karpenterCore.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(karpenter.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(datadoghqv1alpha1.SchemeBuilder.AddToScheme(scheme))

mockctrl := gomock.NewController(t)
castaiclient := mock_castai.NewMockClient(mockctrl)
Expand All @@ -76,6 +78,7 @@ func TestController_HappyPath(t *testing.T) {
provisionersGvr := karpenterCore.SchemeGroupVersion.WithResource("provisioners")
machinesGvr := karpenterCore.SchemeGroupVersion.WithResource("machines")
awsNodeTemplatesGvr := karpenter.SchemeGroupVersion.WithResource("awsnodetemplates")
datadogExtendedDSReplicaSetsGvr := datadoghqv1alpha1.GroupVersion.WithResource("extendeddaemonsetreplicasets")

node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{}}}
expectedNode := node.DeepCopy()
Expand Down Expand Up @@ -163,6 +166,20 @@ func TestController_HappyPath(t *testing.T) {
awsNodeTemplatesData, err := delta.Encode(awsNodeTemplates)
require.NoError(t, err)

datadogExtendedDSReplicaSet := &datadoghqv1alpha1.ExtendedDaemonSetReplicaSet{
TypeMeta: metav1.TypeMeta{
Kind: "ExtendedDaemonSetReplicaSet",
APIVersion: datadogExtendedDSReplicaSetsGvr.GroupVersion().String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: datadogExtendedDSReplicaSetsGvr.Resource,
Namespace: v1.NamespaceDefault,
},
}

datadogExtendedDSReplicaSetData, err := delta.Encode(datadogExtendedDSReplicaSet)
require.NoError(t, err)

fakeSelfSubjectAccessReviewsClient := &authfakev1.FakeSelfSubjectAccessReviews{
Fake: &authfakev1.FakeAuthorizationV1{
Fake: &k8stesting.Fake{},
Expand All @@ -180,7 +197,7 @@ func TestController_HappyPath(t *testing.T) {

clientset := fake.NewSimpleClientset(node, pod, cfgMap, pdb, hpa, csi)
metricsClient := metrics_fake.NewSimpleClientset()
dynamicClient := dynamic_fake.NewSimpleDynamicClient(scheme, provisioners, machines, awsNodeTemplates)
dynamicClient := dynamic_fake.NewSimpleDynamicClient(scheme, provisioners, machines, awsNodeTemplates, datadogExtendedDSReplicaSet)

clientset.Fake.Resources = []*metav1.APIResourceList{
{
Expand Down Expand Up @@ -260,6 +277,17 @@ func TestController_HappyPath(t *testing.T) {
},
},
},
{
GroupVersion: datadogExtendedDSReplicaSetsGvr.GroupVersion().String(),
APIResources: []metav1.APIResource{
{
Group: datadogExtendedDSReplicaSetsGvr.Group,
Name: datadogExtendedDSReplicaSetsGvr.Resource,
Version: datadogExtendedDSReplicaSetsGvr.Version,
Verbs: []string{"get", "list", "watch"},
},
},
},
}

version.EXPECT().Full().Return("1.21+").MaxTimes(3)
Expand All @@ -276,7 +304,7 @@ func TestController_HappyPath(t *testing.T) {
require.Equal(t, clusterID, d.ClusterID)
require.Equal(t, "1.21+", d.ClusterVersion)
require.True(t, d.FullSnapshot)
require.Len(t, d.Items, 9)
require.Len(t, d.Items, 10)

var actualValues []string
for _, item := range d.Items {
Expand All @@ -292,6 +320,7 @@ func TestController_HappyPath(t *testing.T) {
require.Contains(t, actualValues, fmt.Sprintf("%s-%s-%v", castai.EventAdd, "Provisioner", provisionersData))
require.Contains(t, actualValues, fmt.Sprintf("%s-%s-%v", castai.EventAdd, "Machine", machinesData))
require.Contains(t, actualValues, fmt.Sprintf("%s-%s-%v", castai.EventAdd, "AWSNodeTemplate", awsNodeTemplatesData))
require.Contains(t, actualValues, fmt.Sprintf("%s-%s-%v", castai.EventAdd, "ExtendedDaemonSetReplicaSet", datadogExtendedDSReplicaSetData))

return nil
})
Expand Down
2 changes: 2 additions & 0 deletions internal/services/controller/scheme/register.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scheme

import (
datadoghqv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1"
karpenterCore "github.com/aws/karpenter-core/pkg/apis/v1alpha5"
karpenter "github.com/aws/karpenter/pkg/apis/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -25,6 +26,7 @@ var builder = runtime.SchemeBuilder{
policyv1.AddToScheme,
karpenterCore.SchemeBuilder.AddToScheme,
karpenter.SchemeBuilder.AddToScheme,
datadoghqv1alpha1.SchemeBuilder.AddToScheme,
}

func init() {
Expand Down

0 comments on commit 50bf5ac

Please sign in to comment.