-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create grpc deployment when starting operator #332
base: main
Are you sure you want to change the base?
Changes from 8 commits
a637096
5eeb578
8bf94dd
16ee64d
9ed0cf7
8902e02
14280fd
3ec5f36
1d5cecb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,6 +5,17 @@ import ( | |||
|
||||
installationv1 "get.porter.sh/porter/gen/proto/go/porterapis/installation/v1alpha1" | ||||
"google.golang.org/grpc" | ||||
appsv1 "k8s.io/api/apps/v1" | ||||
corev1 "k8s.io/api/core/v1" | ||||
"k8s.io/apimachinery/pkg/api/resource" | ||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
"k8s.io/apimachinery/pkg/util/intstr" | ||||
"k8s.io/utils/ptr" | ||||
) | ||||
|
||||
const ( | ||||
PorterNamespace = "porter-operator-system" | ||||
PorterGRPCName = "porter-grpc-service" | ||||
) | ||||
|
||||
type PorterClient interface { | ||||
|
@@ -15,3 +26,118 @@ type PorterClient interface { | |||
type ClientConn interface { | ||||
Close() error | ||||
} | ||||
|
||||
var GrpcDeployment = &appsv1.Deployment{ | ||||
ObjectMeta: metav1.ObjectMeta{ | ||||
Name: PorterGRPCName, | ||||
Namespace: PorterNamespace, | ||||
Labels: map[string]string{ | ||||
"app": "porter-grpc-service", | ||||
}, | ||||
}, | ||||
Spec: appsv1.DeploymentSpec{ | ||||
Replicas: ptr.To(int32(1)), | ||||
Selector: &metav1.LabelSelector{ | ||||
MatchLabels: map[string]string{ | ||||
"app": "porter-grpc-service", | ||||
}, | ||||
}, | ||||
Template: corev1.PodTemplateSpec{ | ||||
ObjectMeta: metav1.ObjectMeta{ | ||||
Labels: map[string]string{ | ||||
"app": "porter-grpc-service", | ||||
}, | ||||
}, | ||||
Spec: corev1.PodSpec{ | ||||
Containers: []corev1.Container{ | ||||
{ | ||||
Name: "porter-grpc-service", | ||||
Image: "ghcr.io/getporter/server:v1.1.0", | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can me make the image version a const? I think it's fine to have the server version compiled into the operator controller to ensure compatibility but it should be easy to upgrade when we want to release a new version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can update this. |
||||
Ports: []corev1.ContainerPort{ | ||||
{ | ||||
Name: "grpc", | ||||
ContainerPort: 3001, | ||||
}, | ||||
}, | ||||
Args: []string{"api-server", "run"}, | ||||
VolumeMounts: []corev1.VolumeMount{ | ||||
{ | ||||
MountPath: "/porter-config", | ||||
Name: "porter-grpc-service-config-volume", | ||||
}, | ||||
}, | ||||
Resources: corev1.ResourceRequirements{ | ||||
Limits: corev1.ResourceList{ | ||||
corev1.ResourceCPU: resource.MustParse("2000m"), | ||||
corev1.ResourceMemory: resource.MustParse("512Mi"), | ||||
}, | ||||
Requests: corev1.ResourceList{ | ||||
corev1.ResourceCPU: resource.MustParse("100m"), | ||||
corev1.ResourceMemory: resource.MustParse("32Mi"), | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
Volumes: []corev1.Volume{ | ||||
{ | ||||
Name: "porter-grpc-service-config-volume", | ||||
VolumeSource: corev1.VolumeSource{ | ||||
ConfigMap: &corev1.ConfigMapVolumeSource{ | ||||
LocalObjectReference: corev1.LocalObjectReference{ | ||||
Name: "porter-grpc-service-config", | ||||
}, | ||||
Items: []corev1.KeyToPath{ | ||||
{ | ||||
Key: "config", | ||||
Path: "config.yaml", | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
} | ||||
|
||||
var GrpcService = &corev1.Service{ | ||||
ObjectMeta: metav1.ObjectMeta{ | ||||
Name: PorterGRPCName, | ||||
Namespace: PorterNamespace, | ||||
Labels: map[string]string{ | ||||
"app": "porter-grpc-service", | ||||
}, | ||||
}, | ||||
Spec: corev1.ServiceSpec{ | ||||
Ports: []corev1.ServicePort{ | ||||
{ | ||||
Protocol: corev1.ProtocolTCP, | ||||
TargetPort: intstr.FromInt(3001), | ||||
Port: int32(3001), | ||||
}, | ||||
}, | ||||
Selector: map[string]string{"app": "porter-grpc-service"}, | ||||
Type: corev1.ServiceTypeClusterIP, | ||||
}, | ||||
} | ||||
|
||||
var GrpcConfigMap = &corev1.ConfigMap{ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where I think the complexity is for managing the grpc server as part of the controller. The porter config that this uses HAS to be the porter config that the installations used when running so that means it needs to use the porter config for the namespace. We put the restriction in the only allow a single porter config per namespace instead of a porter config to be defined for every installation. The operator sets up a default config if one doesn't exist. This service should be using the porter config that's applied to the namespace, either the default one or the user provided one. It also has to track if that PorterConfig ever changes and then reload with the new config so that it can hit the backing stores where the installations actually live. Btw @schristoff we should add support for moving porter storage data from one backend to another. This will "just work" for secrets as long as the secrets are managed externally for the new store like they should be but for storage backend AFAIK there's no way to move from one DB to another if that changes in the porter config and we should definitely support that! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That means we can't do this implementation because this is trying to install the grpc server before we even do an installation. If the installation needs to happen to success to then create a deployment/configmap/service to get the Porter config in the namespace, (that resource isn't created until something makes it get created) then we will have to do that after the first installation. Relying on the default Porter config at runtime seems a little tricky as that default is making assumption around the installation resource process. What I can do is move this to be done once at setup during the first installation and dynamically create the configmap that will map to the porter config by the installation we have in the namespace once the installation is complete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really interesting because of how the Porter config gets resolved for an AgentAction:
We probably need to create a "default" grpc server in the operator namespace then have namespace specific servers IF a PorterConfig is specified for that namespace BUT not for the system..... This just feels gross.... But the resolvePorterConfig should be able to handle checking if a grpc server exists that will be able to handle the AgentAction based on the PorterConfig that is selected to run that AgentAction |
||||
ObjectMeta: metav1.ObjectMeta{ | ||||
Name: "porter-grpc-service-config", | ||||
Namespace: PorterNamespace, | ||||
}, | ||||
Data: map[string]string{ | ||||
"config": ConfigmMapConfig, | ||||
}, | ||||
} | ||||
|
||||
var ConfigmMapConfig = ` | ||||
default-secrets-plugin: "kubernetes.secrets" | ||||
default-storage: "mongodb" | ||||
storage: | ||||
- name: "mongodb" | ||||
plugin: "mongodb" | ||||
config: | ||||
url: "mongodb://root:demopasswd@porter-operator-mongodb.demo.svc.cluster.local" | ||||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already defined in controllers/installation_controller.go