Skip to content

Commit

Permalink
Kubernetes/MinioS3Server.hs: fill in minio deployment name and pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Aug 3, 2024
1 parent fa3e6b6 commit 87f2806
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ withK8SMinioS3Server' kubectlBinary kcc@(KubernetesClusterContext {..}) MinioOpe
debug [i|Preloading image: #{busyboxImage}|]
loadImageIfNecessary' kcc (ImageLoadSpecDocker busyboxImage IfNotPresent)

(userAndPassword@(username, password), finalYaml) <- case transformKustomizeChunks (toString minioS3ServerNamespace) (T.splitOn "---\n" (toText allYaml)) of
(userAndPassword@(username, password), finalYaml) <- case transformKustomizeChunks (toString minioS3ServerNamespace) (toString deploymentName) (T.splitOn "---\n" (toText allYaml)) of
Left err -> expectationFailure [i|Couldn't transform kustomize chunks: #{err}|]
Right x -> pure x

Expand All @@ -175,6 +175,7 @@ withK8SMinioS3Server' kubectlBinary kcc@(KubernetesClusterContext {..}) MinioOpe
>>= waitForProcess >>= (`shouldBe` ExitSuccess)


-- Create network policy allowing ingress/egress for v1.min.io/tenant = deploymentName
let createNetworkPolicy = do
let (policyName, discoverPodPolicyName, yaml) = networkPolicy deploymentName
createProcessWithLoggingAndStdin ((proc kubectlBinary ["create", "--namespace", toString minioS3ServerNamespace, "-f", "-"]) { env = Just env, delegate_ctlc = True }) yaml
Expand All @@ -184,7 +185,6 @@ withK8SMinioS3Server' kubectlBinary kcc@(KubernetesClusterContext {..}) MinioOpe
runWithKubeConfig kubectlBinary ["delete", "NetworkPolicy", policyName, "--namespace", toString minioS3ServerNamespace]
runWithKubeConfig kubectlBinary ["delete", "NetworkPolicy", discoverPodPolicyName, "--namespace", toString minioS3ServerNamespace]

-- TODO: create network policy allowing ingress/egress for v1.min.io/tenant = deploymentName
bracket createNetworkPolicy destroyNetworkPolicy $ \_ -> bracket create destroy $ \((username, password), _) -> do
do
uuid <- makeUUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ parseMinioUserAndPassword txt = case (userValues, passwordValues) of
-- testInput = [__i|export MINIO_ROOT_USER="WXSTFUWIRS04LMGIMJGV"
-- export MINIO_ROOT_PASSWORD="NCDCfTaiXcGHq8QRfSaXMAWOXgdrhpGwPSkoYMWf"|]

transformKustomizeChunks :: String -> [Text] -> Either String ((Text, Text), Text)
transformKustomizeChunks namespace initialChunks = do
transformKustomizeChunks :: String -> String -> [Text] -> Either String ((Text, Text), Text)
transformKustomizeChunks namespace deploymentName initialChunks = do
userAndPassword <- getUserAndPassword initialChunks

return (userAndPassword, finalYaml)
Expand All @@ -49,6 +49,9 @@ transformKustomizeChunks namespace initialChunks = do
-- Disable TLS
& fmap disableTLS

-- Set deployment name
& fmap (setDeploymentNameAndPoolSize deploymentName)

-- Combine everything into multi-document Yaml
& T.intercalate "---\n"

Expand Down Expand Up @@ -89,5 +92,13 @@ disableTLS (decode -> Right x@(A.Object (aesonLookup "kind" -> Just (A.String "T
& set (_Object . ix "spec" . _Object . at "externalCertSecret") Nothing
disableTLS t = t

setDeploymentNameAndPoolSize :: String -> Text -> Text
setDeploymentNameAndPoolSize deploymentName (decode -> Right x@(A.Object (aesonLookup "kind" -> Just (A.String "Tenant")))) = decodeUtf8 (Yaml.encode x')
where
x' = x
& set (_Object . ix "metadata" . _Object . ix "name") (A.String (toText deploymentName))
& set (_Object . ix "spec" . _Object . ix "pools" . _Array . ix 0 . _Object . ix "servers") (A.Number 1)
setDeploymentNameAndPoolSize _ t = t

decode :: FromJSON a => Text -> Either Yaml.ParseException a
decode = Yaml.decodeEither' . encodeUtf8

0 comments on commit 87f2806

Please sign in to comment.