Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

feat: README + TODOs #5

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# kardinal-operator
# Kardinal Operator

Implementation of [Kardinal](https://github.com/kurtosis-tech/kardinal) as a K8S Operator.

## Development

Minikube + K8S manifest deployed. K8S context set to your local cluster.

The following three commands are commonly used during development:

```
make lint (Run golangci linter. Can also be configured inside your IDE.)
make test (Run tests against local cluster)
make run (Run operator against your local cluster)
```

Manage custom resources with kubectl:

```yaml
apiVersion: core.kardinal.dev/v1
kind: Flow
metadata:
labels:
app.kubernetes.io/name: kardinal
app.kubernetes.io/managed-by: kustomize
name: flow-test
namespace: baseline
spec:
service: frontend
image: kurtosistech/frontend:demo-frontend
```

```
kubectl create -f flow.yaml
kubectl delete -f flow.yaml
```
8 changes: 5 additions & 3 deletions kardinal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ func AddAnnotations(obj *metav1.ObjectMeta, annotations map[string]string) {
}
}

// TODO: Add create, update and delete global options
// TODO: Refactor the Apply... functions
// OPERATOR-TODO: Add create, update and delete global options
// OPERATOR-TODO: Refactor the Apply... functions

func ApplyServiceResources(ctx context.Context, clusterResources *Resources, clusterTopologyResources *Resources, cl client.Client) error {
for _, namespace := range clusterResources.Namespaces {
Expand All @@ -176,6 +176,8 @@ func ApplyServiceResources(ctx context.Context, clusterResources *Resources, clu
}
}
}
// OPERATOR-TODO: Set app and version labels on non-managed service if not already set.
// Those labels are required by Istio.
}
}
}
Expand Down Expand Up @@ -241,7 +243,7 @@ func ApplyDeploymentResources(ctx context.Context, clusterResources *Resources,
/* else {
annotationsToAdd := map[string]string{
"sidecar.istio.io/inject": "true",
// TODO: make this a flag to help debugging
// KARDINAL-TODO: make this a flag to help debugging
// One can view the logs with: kubeclt logs -f -l app=<serviceID> -n <namespace> -c istio-proxy
"sidecar.istio.io/componentLogLevel": "lua:info",
}
Expand Down
8 changes: 4 additions & 4 deletions kardinal/topology/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (service *Service) GetAppsV1Deployment(namespace string) *appsv1.Deployment
deployment.Spec.Template.ObjectMeta = metav1.ObjectMeta{
Annotations: map[string]string{
"sidecar.istio.io/inject": trueStr,
// TODO: make this a flag to help debugging
// KARDINAL-TODO: make this a flag to help debugging
// One can view the logs with: kubeclt logs -f -l app=<serviceID> -n <namespace> -c istio-proxy
"sidecar.istio.io/componentLogLevel": "lua:info",
},
Expand Down Expand Up @@ -195,7 +195,7 @@ func (service *Service) GetVirtualService(services []*Service) (*istioclient.Vir
destinationRule := service.GetDestinationRule(services)

for _, svc := range services {
// TODO: Support for multiple ports
// KARDINAL-TODO: Support for multiple ports
servicePort := &svc.ServiceSpec.Ports[0]
var flowHost *string

Expand Down Expand Up @@ -227,7 +227,7 @@ func (service *Service) GetVirtualService(services []*Service) (*istioclient.Vir
}

func (service *Service) GetDestinationRule(services []*Service) *istioclient.DestinationRule {
// TODO(shared-annotation) - we could store "shared" versions somewhere so that the pointers are the same
// KARDINAL-TODO(shared-annotation) - we could store "shared" versions somewhere so that the pointers are the same
// if we do that then the render work around isn't necessary
subsets := lo.UniqBy(
lo.Map(services, func(svc *Service, _ int) *v1alpha3.Subset {
Expand All @@ -238,7 +238,7 @@ func (service *Service) GetDestinationRule(services []*Service) *istioclient.Des
},
}

// TODO Narrow down this configuration to only subsets created for telepresence intercepts or find a way to enable TLS for telepresence intercepts https://github.com/kurtosis-tech/kardinal-kontrol/issues/14
// KARDINAL-TODO Narrow down this configuration to only subsets created for telepresence intercepts or find a way to enable TLS for telepresence intercepts https://github.com/kurtosis-tech/kardinal-kontrol/issues/14
// This config is necessary for Kardinal/Telepresence (https://www.telepresence.io/) integration
if svc.IsManaged {
newTrafficPolicy := &v1alpha3.TrafficPolicy{
Expand Down
14 changes: 6 additions & 8 deletions kardinal/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (clusterTopology *ClusterTopology) UpdateWithFlow(
clusterTopology.UpdateDependencies(service, modifiedService)

// create versioned parents for non http stateful services
// TODO - this should be done for all non http services and not just the stateful ones
// KARDINAL-TODO - this should be done for all non http services and not just the stateful ones
// every child should be copied; immediate parent duplicated
// if children of non http services support http then our routing will have to be modified
// we should treat those http services as non http; a hack could be to remove the appProtocol HTTP marking
Expand Down Expand Up @@ -178,7 +178,7 @@ func (clusterTopology *ClusterTopology) GetResources() (*resources.Resources, er
})
for _, services := range groupedServices {
if len(services) > 0 {
// TODO: this assumes service specs didn't change. May we need a new version to ClusterTopology data structure
// KARDINAL-TODO: this assumes service specs didn't change. May we need a new version to ClusterTopology data structure

// ServiceSpec is nil for external services - don't process anything bc theres nothing to add to the cluster
if services[0].ServiceSpec == nil {
Expand All @@ -190,7 +190,7 @@ func (clusterTopology *ClusterTopology) GetResources() (*resources.Resources, er
resourceNamespace.VirtualServices = append(resourceNamespace.VirtualServices, virtualService)
resourceNamespace.DestinationRules = append(resourceNamespace.DestinationRules, destinationRule)

// TODO: Add authz policies
// OPERATOR-TODO: Add authz policies
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ func (clusterTopology *ClusterTopology) ApplyResources(ctx context.Context, clus
return stacktrace.Propagate(err, "An error occurred applying the virtual service resources")
}

// TODO: Apply ingress resources
// OPERATOR-TODO: Apply ingress resources
/* err = resources.ApplyIngressResources(ctx, clusterResources, clusterTopologyResources, cl)
if err != nil {
return stacktrace.Propagate(err, "An error occurred applying the ingress resources")
Expand Down Expand Up @@ -319,9 +319,7 @@ func (clusterTopology *ClusterTopology) Merge(clusterTopologies []*ClusterTopolo
mergedClusterTopology.Ingress.ActiveFlowIDs = lo.Uniq(mergedClusterTopology.Ingress.ActiveFlowIDs)
logrus.Infof("Services length: %d", len(mergedClusterTopology.Services))

// TODO improve the filtering method, we could implement the `Service.Equal` method to compare and filter the services
// TODO and inside this method we could use the k8s service marshall method (https://pkg.go.dev/k8s.io/api/core/v1#Service.Marsha) and also the same for other k8s fields
// TODO it should be faster
// KARDINAL-TODO improve the filtering method, we could implement the `Service.Equal` method to compare and filter the services and inside this method we could use the k8s service marshall method (https://pkg.go.dev/k8s.io/api/core/v1#Service.Marsha) and also the same for other k8s fields it should be faster
mergedClusterTopology.Services = lo.UniqBy(mergedClusterTopology.Services, func(service *Service) ServiceVersion {
serviceVersion := ServiceVersion{
ServiceID: service.ServiceID,
Expand Down Expand Up @@ -473,7 +471,7 @@ func processServices(services []*corev1.Service, deployments []*appsv1.Deploymen
clusterTopologyServices = append(clusterTopologyServices, clusterTopologyService)
}

// TODO: Use the dependency CRs instead
// OPERATOR-TODO: Use the dependency CRs instead
for _, svcWithDependenciesAnnotation := range serviceWithDependencies {

serviceAndPorts := strings.Split(svcWithDependenciesAnnotation.dependenciesAnnotation, ",")
Expand Down
Loading