resources

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostIPConfigKey = "operator.host_ip"
)

Variables

View Source
var (
	DefaultInstall = &v1.Install{
		ObjectMeta: metav1.ObjectMeta{
			Name:      "install",
			Namespace: "home-cloud-system",
		},
		Spec: v1.InstallSpec{
			GatewayAPI: &v1.GatewayAPISpec{},
			Istio: &v1.IstioSpec{
				Namespace: "istio-system",

				IngressGatewayName: "ingress-gateway",
				Base:               &v1.BaseSpec{},
				Istiod: &v1.IstiodSpec{

					Values: `
resources:
  requests:
    cpu: 100m
    memory: 100Mi
`,
				},
				CNI: &v1.CNISpec{},
				Ztunnel: &v1.ZtunnelSpec{

					Values: `
resources:
  requests:
    cpu: 100m
    memory: 100Mi
`,
				},
			},
			CertManager: &v1.CertManagerSpec{
				Namespace: "cert-manager",
				Values: `
crds:
  enabled: true
`,
			},
			Blocky:              &v1.BlockySpec{},
			GenericDevicePlugin: &v1.GenericDevicePluginSpec{},
			MDNS:                &v1.MDNSSpec{},
			Tunnel:              &v1.TunnelSpec{},
			Operator:            &v1.OperatorSpec{},
			Daemon: &v1.DaemonSpec{
				System:     &v1.SystemSpec{},
				Kubernetes: &v1.KubernetesSpec{},
			},
			Settings: &v1.SettingsSpec{
				StorageApps: []string{
					"filebrowser",
					"nextexplorer",
				},
				Network: v1.NetworkSettingsSpec{
					Domain: "home-cloud.local",
					DNS: v1.DNSNetworkSettingsSpec{
						UpstreamServers: []string{"1.1.1.1", "1.0.0.1"},
						DenyListSources: []string{"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"},
					},
				},
			},
		},
		Status: v1.InstallStatus{
			GatewayAPI:          &v1.GatewayAPIStatus{},
			Istio:               &v1.IstioStatus{},
			GenericDevicePlugin: &v1.GenericDevicePluginStatus{},
			MDNS:                &v1.MDNSStatus{},
			Tunnel:              &v1.TunnelStatus{},
			Operator:            &v1.OperatorStatus{},
			Daemon:              &v1.DaemonStatus{},
		},
	}

	Certificates = func(install *v1.Install) []client.Object {
		return []client.Object{
			&cmv1.ClusterIssuer{
				ObjectMeta: metav1.ObjectMeta{
					Name: "selfsigned-issuer",
				},
				Spec: cmv1.IssuerSpec{
					IssuerConfig: cmv1.IssuerConfig{
						SelfSigned: &cmv1.SelfSignedIssuer{},
					},
				},
			},
			&cmv1.Certificate{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "selfsigned-ca",
					Namespace: install.Spec.CertManager.Namespace,
				},
				Spec: cmv1.CertificateSpec{
					IsCA:       true,
					CommonName: "home-cloud-selfsigned-ca",
					SecretName: "root-ca-secret",
					Duration: &metav1.Duration{
						Duration: time.Hour * 87600,
					},
					RenewBefore: &metav1.Duration{
						Duration: time.Hour * 78840,
					},
					PrivateKey: &cmv1.CertificatePrivateKey{
						Algorithm: cmv1.ECDSAKeyAlgorithm,
						Size:      256,
						Encoding:  cmv1.PKCS8,
					},
					IssuerRef: cmmetav1.IssuerReference{
						Name: "selfsigned-issuer",
						Kind: cmv1.ClusterIssuerKind,
					},
				},
			},
			&cmv1.ClusterIssuer{
				ObjectMeta: metav1.ObjectMeta{
					Name: "selfsigned-ca-issuer",
				},
				Spec: cmv1.IssuerSpec{
					IssuerConfig: cmv1.IssuerConfig{
						CA: &cmv1.CAIssuer{
							SecretName: "root-ca-secret",
						},
					},
				},
			},
			&cmv1.Certificate{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "gateway",
					Namespace: install.Spec.Istio.Namespace,
				},
				Spec: cmv1.CertificateSpec{
					SecretName: "gateway-cert",
					DNSNames: []string{
						install.Spec.Settings.Network.Domain,
						fmt.Sprintf("*.%s", install.Spec.Settings.Network.Domain),
					},
					PrivateKey: &cmv1.CertificatePrivateKey{
						Algorithm: cmv1.ECDSAKeyAlgorithm,
						Size:      256,
						Encoding:  cmv1.PKCS8,
					},
					IssuerRef: cmmetav1.IssuerReference{
						Name: "selfsigned-ca-issuer",
						Kind: cmv1.ClusterIssuerKind,
					},
				},
			},
		}
	}

	GenericDevicePluginObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&appsv1.DaemonSet{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "generic-device-plugin",
					Namespace: "kube-system",
					Labels: map[string]string{
						"app.kubernetes.io/name": "generic-device-plugin",
					},
				},
				Spec: appsv1.DaemonSetSpec{
					Selector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"app.kubernetes.io/name": "generic-device-plugin",
						},
					},
					Template: corev1.PodTemplateSpec{
						ObjectMeta: metav1.ObjectMeta{
							Labels: map[string]string{
								"app.kubernetes.io/name": "generic-device-plugin",
							},
						},
						Spec: corev1.PodSpec{
							PriorityClassName: "system-node-critical",
							Tolerations: []corev1.Toleration{
								{
									Operator: corev1.TolerationOpExists,
									Effect:   corev1.TaintEffectNoExecute,
								},
								{
									Operator: corev1.TolerationOpExists,
									Effect:   corev1.TaintEffectNoSchedule,
								},
							},
							Containers: []corev1.Container{
								{
									Name:  "generic-device-plugin",
									Image: fmt.Sprintf("%s:%s", install.Spec.GenericDevicePlugin.Image, install.Spec.GenericDevicePlugin.Tag),
									SecurityContext: &corev1.SecurityContext{
										Privileged: ptr.To(true),
									},
									Args: []string{
										"--device",
										`name: serial
groups:
  - paths:
      - path: /dev/ttyUSB*`,
									},
									Resources: corev1.ResourceRequirements{
										Requests: corev1.ResourceList{
											corev1.ResourceCPU:    resource.MustParse("50m"),
											corev1.ResourceMemory: resource.MustParse("10Mi"),
										},
										Limits: corev1.ResourceList{
											corev1.ResourceCPU:    resource.MustParse("50m"),
											corev1.ResourceMemory: resource.MustParse("20Mi"),
										},
									},
									Ports: []corev1.ContainerPort{
										{
											Name:          "http",
											ContainerPort: 8080,
										},
									},
									VolumeMounts: []corev1.VolumeMount{
										{
											Name:      "device-plugin",
											MountPath: "/var/lib/kubelet/device-plugins",
										},
										{
											Name:      "dev",
											MountPath: "/dev",
										},
									},
								},
							},
							Volumes: []corev1.Volume{
								{
									Name: "device-plugin",
									VolumeSource: corev1.VolumeSource{
										HostPath: &corev1.HostPathVolumeSource{
											Path: "/var/lib/kubelet/device-plugins",
										},
									},
								},
								{
									Name: "dev",
									VolumeSource: corev1.VolumeSource{
										HostPath: &corev1.HostPathVolumeSource{
											Path: "/dev",
										},
									},
								},
							},
						},
					},
					UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
						Type: appsv1.RollingUpdateDaemonSetStrategyType,
					},
				},
			},
		}
	}
)
View Source
var (
	BlockyObjects = func(install *v1.Install) []client.Object {
		bconfig := BlockyConfig{
			Upstreams: BlockyUpstreams{
				Groups: map[string][]string{
					"default": install.Spec.Settings.Network.DNS.UpstreamServers,
				},
			},
			Ports: BlockyPorts{
				DNS:  53,
				HTTP: 4000,
			},
			Blocking: BlockyBlocking{
				DenyLists: map[string][]string{
					"main": combineDomainsAndSources(install.Spec.Settings.Network.DNS.DenyDomains, install.Spec.Settings.Network.DNS.DenyListSources),
				},
				AllowLists: map[string][]string{
					"main": combineDomainsAndSources(install.Spec.Settings.Network.DNS.AllowDomains, install.Spec.Settings.Network.DNS.AllowListSources),
				},
				ClientGroupsBlock: map[string][]string{
					"default": {
						"main",
					},
				},
			},
			CustomDNS: BlockyCustomDNS{
				CustomTTL: "1h",
				Mapping: map[string]string{
					install.Spec.Settings.Network.Domain: chassis.GetConfig().GetString(HostIPConfigKey),
				},
			},
		}

		byaml, err := yaml.Marshal(bconfig)
		if err != nil {

			return make([]client.Object, 0)
		}

		return []client.Object{
			&corev1.ConfigMap{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "blocky",
					Namespace: install.Namespace,
				},
				Data: map[string]string{
					"config.yml": string(byaml),
				},
			},
			&corev1.Service{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "blocky",
					Namespace: install.Namespace,
					Labels: map[string]string{
						"app": "blocky",
					},
				},
				Spec: corev1.ServiceSpec{
					Type: corev1.ServiceTypeNodePort,
					Ports: []corev1.ServicePort{
						{
							Name:       "tcp",
							Protocol:   corev1.ProtocolTCP,
							NodePort:   53,
							Port:       53,
							TargetPort: intstr.FromInt(53),
						},
						{
							Name:       "udp",
							Protocol:   corev1.ProtocolUDP,
							NodePort:   53,
							Port:       53,
							TargetPort: intstr.FromInt(53),
						},
					},
					Selector: map[string]string{
						"app": "blocky",
					},
				},
			},
			&appsv1.Deployment{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "blocky",
					Namespace: install.Namespace,
				},
				Spec: appsv1.DeploymentSpec{
					Replicas: ptr.To[int32](1),
					Selector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"app": "blocky",
						},
					},
					Template: corev1.PodTemplateSpec{
						ObjectMeta: metav1.ObjectMeta{
							Labels: map[string]string{
								"app": "blocky",

								"istio.io/dataplane-mode": "none",
							},
							Annotations: map[string]string{

								"checksum/config": kube.ComputeSHA256Sum(string(byaml)),
							},
						},
						Spec: corev1.PodSpec{
							Containers: []corev1.Container{
								{
									Name:  "blocky",
									Image: fmt.Sprintf("%s:%s", install.Spec.Blocky.Image, install.Spec.Blocky.Tag),
									Ports: []corev1.ContainerPort{
										{
											Name:          "tcp",
											Protocol:      corev1.ProtocolTCP,
											ContainerPort: 53,
										},
										{
											Name:          "udp",
											Protocol:      corev1.ProtocolUDP,
											ContainerPort: 53,
										},
										{
											Name:          "http",
											Protocol:      corev1.ProtocolTCP,
											ContainerPort: 4000,
										},
									},
									LivenessProbe: &corev1.Probe{
										ProbeHandler: corev1.ProbeHandler{
											HTTPGet: &corev1.HTTPGetAction{
												Path: "/",
												Port: intstr.FromString("http"),
											},
										},
									},
									ReadinessProbe: &corev1.Probe{
										ProbeHandler: corev1.ProbeHandler{
											HTTPGet: &corev1.HTTPGetAction{
												Path: "/",
												Port: intstr.FromString("http"),
											},
										},
									},
									VolumeMounts: []corev1.VolumeMount{
										{
											Name:      "config",
											MountPath: "/app/config.yml",
											SubPath:   "config.yml",
										},
									},
								},
							},
							Volumes: []corev1.Volume{
								{
									Name: "config",
									VolumeSource: corev1.VolumeSource{
										ConfigMap: &corev1.ConfigMapVolumeSource{
											LocalObjectReference: corev1.LocalObjectReference{Name: "blocky"},
										},
									},
								},
							},
						},
					},
				},
			},
		}
	}
)
View Source
var (
	DaemonObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&talos.ServiceAccount{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "talos-api-access",
					Namespace: install.Namespace,
				},
				Spec: talos.ServiceAccountSpec{
					Roles: []string{
						"os:admin",
					},
				},
			},
			&corev1.ConfigMap{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "daemon",
					Namespace: install.Namespace,
				},
				Data: map[string]string{
					"config.yaml": `
service:
  name: daemon
  domain: home-cloud
  env: prod
`},
			},
			&appsv1.Deployment{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "daemon",
					Namespace: install.Namespace,
				},
				Spec: appsv1.DeploymentSpec{
					Replicas: ptr.To[int32](1),
					Selector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"app": "daemon",
						},
					},
					Template: corev1.PodTemplateSpec{
						ObjectMeta: metav1.ObjectMeta{
							Labels: map[string]string{
								"app": "daemon",
							},
						},
						Spec: corev1.PodSpec{
							Containers: []corev1.Container{
								{
									Name:  "daemon",
									Image: fmt.Sprintf("%s:%s", install.Spec.Daemon.Image, install.Spec.Daemon.Tag),
									Ports: []corev1.ContainerPort{
										{
											Name:          "http",
											Protocol:      corev1.ProtocolTCP,
											ContainerPort: 8090,
										},
									},

									VolumeMounts: []corev1.VolumeMount{
										{
											Name:      "config",
											MountPath: "/etc/config.yaml",
											SubPath:   "config.yaml",
										},
										{
											Name:      "talos-secrets",
											MountPath: "/var/run/secrets/talos.dev",
										},
									},
								},
							},
							Volumes: []corev1.Volume{
								{
									Name: "config",
									VolumeSource: corev1.VolumeSource{ConfigMap: &corev1.ConfigMapVolumeSource{
										LocalObjectReference: corev1.LocalObjectReference{Name: "daemon"},
									}},
								},
								{
									Name: "talos-secrets",
									VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{
										SecretName: "talos-api-access",
									}},
								},
							},
						},
					},
				},
			},
			&corev1.Service{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "daemon",
					Namespace: install.Namespace,
					Labels: map[string]string{
						"app": "daemon",
					},
				},
				Spec: corev1.ServiceSpec{
					Type: corev1.ServiceTypeClusterIP,
					Ports: []corev1.ServicePort{
						{
							Name:       "http",
							Port:       80,
							TargetPort: intstr.FromInt(8090),
						},
					},
					Selector: map[string]string{
						"app": "daemon",
					},
				},
			},
		}
	}
)
View Source
var (
	GatewayObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&gwv1.Gateway{
				ObjectMeta: metav1.ObjectMeta{
					Name:      install.Spec.Istio.IngressGatewayName,
					Namespace: install.Spec.Istio.Namespace,
				},
				Spec: gwv1.GatewaySpec{
					GatewayClassName: "istio",
					Listeners: []gwv1.Listener{
						{
							Name:     "http",
							Port:     80,
							Protocol: gwv1.HTTPProtocolType,
							AllowedRoutes: &gwv1.AllowedRoutes{
								Namespaces: &gwv1.RouteNamespaces{
									From: ptr.To[gwv1.FromNamespaces]("All"),
								},
							},
						},
						{
							Name:     "https",
							Port:     443,
							Protocol: gwv1.HTTPSProtocolType,
							AllowedRoutes: &gwv1.AllowedRoutes{
								Namespaces: &gwv1.RouteNamespaces{
									From: ptr.To[gwv1.FromNamespaces]("All"),
								},
							},
							TLS: &gwv1.ListenerTLSConfig{
								CertificateRefs: []gwv1.SecretObjectReference{
									{
										Name: "gateway-cert",
									},
								},
							},
						},
					},
					Infrastructure: &gwv1.GatewayInfrastructure{
						ParametersRef: &gwv1.LocalParametersReference{
							Kind: gwv1.Kind("ConfigMap"),
							Name: fmt.Sprintf("%s-options", install.Spec.Istio.IngressGatewayName),
						},
					},
				},
			},
			&corev1.ConfigMap{
				ObjectMeta: metav1.ObjectMeta{
					Name:      fmt.Sprintf("%s-options", install.Spec.Istio.IngressGatewayName),
					Namespace: install.Spec.Istio.Namespace,
				},
				Data: map[string]string{
					"service": `spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 80
  - port: 443
    nodePort: 443
`,
				},
			},
			&gwv1.HTTPRoute{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "operator",
					Namespace: install.Namespace,
				},
				Spec: gwv1.HTTPRouteSpec{
					CommonRouteSpec: gwv1.CommonRouteSpec{
						ParentRefs: []gwv1.ParentReference{
							{
								Name:      gwv1.ObjectName(install.Spec.Istio.IngressGatewayName),
								Namespace: ptr.To(gwv1.Namespace(install.Spec.Istio.Namespace)),
							},
						},
					},
					Hostnames: []gwv1.Hostname{
						gwv1.Hostname(install.Spec.Settings.Network.Domain),
						gwv1.Hostname(fmt.Sprintf("admin.%s", install.Spec.Settings.Network.Domain)),
					},
					Rules: []gwv1.HTTPRouteRule{
						{
							BackendRefs: []gwv1.HTTPBackendRef{
								{
									BackendRef: gwv1.BackendRef{
										BackendObjectReference: gwv1.BackendObjectReference{
											Name: "operator",
											Port: ptr.To[gwv1.PortNumber](80),
										},
									},
								},
							},
						},
					},
				},
			},
		}
	}
)
View Source
var (
	MDNSObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&corev1.ServiceAccount{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "mdns",
					Namespace: install.Namespace,
				},
			},
			&rbacv1.ClusterRole{
				ObjectMeta: metav1.ObjectMeta{
					Name: "home-cloud-mdns",
				},
				Rules: []rbacv1.PolicyRule{
					{
						Verbs: []string{
							"list",
							"watch",
						},
						APIGroups: []string{""},
						Resources: []string{"services"},
					},
				},
			},
			&rbacv1.ClusterRoleBinding{
				ObjectMeta: metav1.ObjectMeta{
					Name: "home-cloud-mdns-reader",
				},
				Subjects: []rbacv1.Subject{
					{
						Kind:      "ServiceAccount",
						Name:      "mdns",
						Namespace: install.Namespace,
					},
				},
				RoleRef: rbacv1.RoleRef{
					APIGroup: "rbac.authorization.k8s.io",
					Kind:     "ClusterRole",
					Name:     "home-cloud-mdns",
				},
			},
			&corev1.ConfigMap{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "mdns",
					Namespace: install.Namespace,
				},
				Data: map[string]string{
					"config.yaml": `
service:
  name: mdns
  domain: home-cloud
  env: prod
`},
			},
			&appsv1.StatefulSet{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "mdns",
					Namespace: install.Namespace,
				},
				Spec: appsv1.StatefulSetSpec{
					Replicas: ptr.To[int32](1),
					Selector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"app": "mdns",
						},
					},
					Template: corev1.PodTemplateSpec{
						ObjectMeta: metav1.ObjectMeta{
							Labels: map[string]string{
								"app": "mdns",
							},
						},
						Spec: corev1.PodSpec{
							ServiceAccountName: "mdns",

							HostNetwork: true,
							Containers: []corev1.Container{
								{
									Name:  "mdns",
									Image: fmt.Sprintf("%s:%s", install.Spec.MDNS.Image, install.Spec.MDNS.Tag),
									SecurityContext: &corev1.SecurityContext{
										RunAsUser:                ptr.To(int64(65534)),
										RunAsGroup:               ptr.To(int64(65534)),
										RunAsNonRoot:             ptr.To(true),
										ReadOnlyRootFilesystem:   ptr.To(true),
										AllowPrivilegeEscalation: ptr.To(false),
										SeccompProfile: &corev1.SeccompProfile{
											Type: corev1.SeccompProfileTypeRuntimeDefault,
										},
										Capabilities: &corev1.Capabilities{
											Drop: []corev1.Capability{
												"ALL",
											},
										},
									},
									Env: []corev1.EnvVar{
										{
											Name: "DRAFT_MDNS_HOST_IP",
											ValueFrom: &corev1.EnvVarSource{
												FieldRef: &corev1.ObjectFieldSelector{
													FieldPath: "status.hostIP",
												},
											},
										},
									},

									VolumeMounts: []corev1.VolumeMount{
										{
											Name:      "config",
											MountPath: "/etc/config.yaml",
											SubPath:   "config.yaml",
										},
									},
								},
							},
							Volumes: []corev1.Volume{
								{
									Name: "config",
									VolumeSource: corev1.VolumeSource{
										ConfigMap: &corev1.ConfigMapVolumeSource{
											LocalObjectReference: corev1.LocalObjectReference{Name: "mdns"},
										},
									},
								},
							},
						},
					},
				},
			},
		}
	}
)
View Source
var (
	NamespaceObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&corev1.Namespace{
				ObjectMeta: metav1.ObjectMeta{
					Name: install.Spec.Istio.Namespace,
					Labels: map[string]string{
						"pod-security.kubernetes.io/enforce": "privileged",
					},
				},
			},
			&corev1.Namespace{
				ObjectMeta: metav1.ObjectMeta{
					Name: install.Spec.CertManager.Namespace,
					Labels: map[string]string{
						"istio.io/dataplane-mode": "ambient",
					},
				},
			},
			&corev1.Namespace{
				ObjectMeta: metav1.ObjectMeta{

					Name: install.Namespace,
					Labels: map[string]string{
						"pod-security.kubernetes.io/enforce": "privileged",
						"istio.io/dataplane-mode":            "ambient",
					},
				},
			},
		}
	}
)
View Source
var (
	// NOTE: For these resources specifically, they have the TypeMeta manually configured.
	//       This is not necessary for most usecases but it allows `tools/releaser` to use
	//       these definitions to create the releasable `operator.yaml` consistent with what
	//       the operator will reconcile itself.
	OperatorObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&corev1.ServiceAccount{
				TypeMeta: metav1.TypeMeta{
					APIVersion: "v1",
					Kind:       "ServiceAccount",
				},
				ObjectMeta: metav1.ObjectMeta{
					Name:      "operator",
					Namespace: install.Namespace,
				},
			},
			&rbacv1.ClusterRoleBinding{
				TypeMeta: metav1.TypeMeta{
					APIVersion: "rbac.authorization.k8s.io/v1",
					Kind:       "ClusterRoleBinding",
				},
				ObjectMeta: metav1.ObjectMeta{
					Name: "operator-rolebinding",
				},
				RoleRef: rbacv1.RoleRef{
					APIGroup: "rbac.authorization.k8s.io",
					Kind:     "ClusterRole",
					Name:     "cluster-admin",
				},
				Subjects: []rbacv1.Subject{
					{
						Kind:      "ServiceAccount",
						Name:      "operator",
						Namespace: install.Namespace,
					},
				},
			},
			&corev1.ConfigMap{
				TypeMeta: metav1.TypeMeta{
					APIVersion: "v1",
					Kind:       "ConfigMap",
				},
				ObjectMeta: metav1.ObjectMeta{
					Name:      "operator",
					Namespace: install.Namespace,
				},
				Data: map[string]string{
					"config.yaml": `service:
  name: operator
  domain: home-cloud
  env: prod
`},
			},
			&appsv1.Deployment{
				TypeMeta: metav1.TypeMeta{
					APIVersion: "apps/v1",
					Kind:       "Deployment",
				},
				ObjectMeta: metav1.ObjectMeta{
					Name:      "operator",
					Namespace: install.Namespace,
				},
				Spec: appsv1.DeploymentSpec{
					Replicas: ptr.To[int32](1),
					Selector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"app": "operator",
						},
					},
					Template: corev1.PodTemplateSpec{
						ObjectMeta: metav1.ObjectMeta{
							Labels: map[string]string{
								"app": "operator",
							},
						},
						Spec: corev1.PodSpec{
							TerminationGracePeriodSeconds: ptr.To(int64(10)),
							ServiceAccountName:            "operator",
							Containers: []corev1.Container{
								{
									Name:  "operator",
									Image: fmt.Sprintf("%s:%s", install.Spec.Operator.Image, install.Spec.Operator.Tag),
									Env: []corev1.EnvVar{
										{
											Name: "DRAFT_OPERATOR_HOST_IP",
											ValueFrom: &corev1.EnvVarSource{
												FieldRef: &corev1.ObjectFieldSelector{
													FieldPath: "status.hostIP",
												},
											},
										},
									},
									Ports: []corev1.ContainerPort{
										{
											Name:          "http",
											Protocol:      corev1.ProtocolTCP,
											ContainerPort: 8090,
										},
									},
									LivenessProbe: &corev1.Probe{
										ProbeHandler: corev1.ProbeHandler{
											HTTPGet: &corev1.HTTPGetAction{
												Path: "/",
												Port: intstr.FromString("http"),
											},
										},
									},
									ReadinessProbe: &corev1.Probe{
										ProbeHandler: corev1.ProbeHandler{
											HTTPGet: &corev1.HTTPGetAction{
												Path: "/",
												Port: intstr.FromString("http"),
											},
										},
									},
									VolumeMounts: []corev1.VolumeMount{
										{
											Name:      "config",
											MountPath: "/etc/config.yaml",
											SubPath:   "config.yaml",
										},
									},
								},
							},
							Volumes: []corev1.Volume{
								{
									Name: "config",
									VolumeSource: corev1.VolumeSource{
										ConfigMap: &corev1.ConfigMapVolumeSource{
											LocalObjectReference: corev1.LocalObjectReference{Name: "operator"},
										},
									},
								},
							},
						},
					},
				},
			},
			&corev1.Service{
				TypeMeta: metav1.TypeMeta{
					APIVersion: "v1",
					Kind:       "Service",
				},
				ObjectMeta: metav1.ObjectMeta{
					Name:      "operator",
					Namespace: install.Namespace,
					Labels: map[string]string{
						"app": "operator",
					},
					Annotations: map[string]string{

						v1.AnnotationDNSHostnames: GenerateDNSValue(install, "home-cloud"),
					},
				},
				Spec: corev1.ServiceSpec{
					Type: corev1.ServiceTypeClusterIP,
					Ports: []corev1.ServicePort{
						{
							Name:       "http",
							Port:       80,
							TargetPort: intstr.FromInt(8090),
						},
					},
					Selector: map[string]string{
						"app": "operator",
					},
				},
			},
		}
	}
)
View Source
var (
	TalosObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&talos.ServiceAccount{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "talos-api-access",
					Namespace: install.Namespace,
				},
				Spec: talos.ServiceAccountSpec{
					Roles: []string{
						"os:admin",
					},
				},
			},
		}
	}
)
View Source
var (
	TunnelObjects = func(install *v1.Install) []client.Object {
		return []client.Object{
			&corev1.ServiceAccount{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "tunnel",
					Namespace: install.Namespace,
				},
			},
			&rbacv1.ClusterRole{
				ObjectMeta: metav1.ObjectMeta{
					Name: "home-cloud-tunnel",
				},
				Rules: []rbacv1.PolicyRule{
					{
						Verbs: []string{
							"*",
						},
						APIGroups: []string{"home-cloud.io"},
						Resources: []string{"wireguards"},
					},
					{
						Verbs: []string{
							"*",
						},
						APIGroups: []string{"home-cloud.io"},
						Resources: []string{"wireguards/status"},
					},
					{
						Verbs: []string{
							"get",
							"list",
							"watch",
						},
						APIGroups: []string{""},
						Resources: []string{"secrets"},
					},
				},
			},
			&rbacv1.ClusterRoleBinding{
				ObjectMeta: metav1.ObjectMeta{
					Name: "home-cloud-tunnel",
				},
				Subjects: []rbacv1.Subject{
					{
						Kind:      "ServiceAccount",
						Name:      "tunnel",
						Namespace: install.Namespace,
					},
				},
				RoleRef: rbacv1.RoleRef{
					APIGroup: "rbac.authorization.k8s.io",
					Kind:     "ClusterRole",
					Name:     "home-cloud-tunnel",
				},
			},
			&corev1.ConfigMap{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "tunnel",
					Namespace: install.Namespace,
				},
				Data: map[string]string{
					"config.yaml": `
service:
  name: tunnel
  domain: home-cloud
  env: prod
  network:
    bind_port: 8091
`},
			},
			&appsv1.StatefulSet{
				ObjectMeta: metav1.ObjectMeta{
					Name:      "tunnel",
					Namespace: install.Namespace,
				},
				Spec: appsv1.StatefulSetSpec{
					Replicas: ptr.To[int32](1),
					Selector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"app": "tunnel",
						},
					},
					Template: corev1.PodTemplateSpec{
						ObjectMeta: metav1.ObjectMeta{
							Labels: map[string]string{
								"app": "tunnel",
							},
						},
						Spec: corev1.PodSpec{
							ServiceAccountName: "tunnel",

							HostNetwork: true,
							Containers: []corev1.Container{
								{
									Name:  "tunnel",
									Image: fmt.Sprintf("%s:%s", install.Spec.Tunnel.Image, install.Spec.Tunnel.Tag),
									SecurityContext: &corev1.SecurityContext{
										Privileged: ptr.To(true),
										Capabilities: &corev1.Capabilities{
											Add: []corev1.Capability{
												"NET_ADMIN",
											},
										},
									},

									VolumeMounts: []corev1.VolumeMount{
										{
											Name:      "config",
											MountPath: "/etc/config.yaml",
											SubPath:   "config.yaml",
										},
									},
								},
							},
							Volumes: []corev1.Volume{
								{
									Name: "config",
									VolumeSource: corev1.VolumeSource{
										ConfigMap: &corev1.ConfigMapVolumeSource{
											LocalObjectReference: corev1.LocalObjectReference{Name: "tunnel"},
										},
									},
								},
							},
						},
					},
				},
			},
		}
	}
)

Functions

func GenerateDNSValue added in v0.2.0

func GenerateDNSValue(install *v1.Install, label string) string

Types

type BlockyBlocking added in v0.3.0

type BlockyBlocking struct {
	DenyLists         map[string][]string `yaml:"denylists"`  // intentionally lowercase
	AllowLists        map[string][]string `yaml:"allowlists"` // intentionally lowercase
	ClientGroupsBlock map[string][]string `yaml:"clientGroupsBlock"`
}

type BlockyConfig added in v0.3.0

type BlockyConfig struct {
	Upstreams BlockyUpstreams
	Ports     BlockyPorts
	Blocking  BlockyBlocking
	CustomDNS BlockyCustomDNS `yaml:"customDNS"`
}

type BlockyCustomDNS added in v0.3.0

type BlockyCustomDNS struct {
	CustomTTL string `yaml:"customTTL"`
	Mapping   map[string]string
}

type BlockyPorts added in v0.3.0

type BlockyPorts struct {
	DNS  int
	HTTP int
}

type BlockyUpstreams added in v0.3.0

type BlockyUpstreams struct {
	Groups map[string][]string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL