Skip to content

Commit

Permalink
ipfs,peer: reconcile profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mFarghaly committed May 20, 2021
1 parent ec5f8f7 commit 9eaaa73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions controllers/ipfs/config_ipfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ set -e

ipfs config Addresses.API /ip4/$IPFS_API_HOST/tcp/$IPFS_API_PORT
ipfs config Addresses.Gateway /ip4/$IPFS_GATEWAY_HOST/tcp/$IPFS_GATEWAY_PORT

export IFS=";"
for profile in $IPFS_PROFILES; do
ipfs config profile apply $profile
echo "$profile profile has been applied"
done
21 changes: 15 additions & 6 deletions controllers/ipfs/peer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type PeerReconciler struct {

var (
//go:embed init_ipfs_config.sh
initIPFSConfig string
initIPFSConfigScript string
//go:embed copy_swarm_key.sh
copySwarmKey string
copySwarmKeyScript string
//go:embed config_ipfs.sh
configIPFS string
configIPFSScript string
)

// +kubebuilder:rbac:groups=ipfs.kotal.io,resources=peers,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -192,9 +192,9 @@ func (r *PeerReconciler) specConfigmap(peer *ipfsv1alpha1.Peer, config *corev1.C
if config.Data == nil {
config.Data = make(map[string]string)
}
config.Data["init_ipfs_config.sh"] = initIPFSConfig
config.Data["copy_swarm_key.sh"] = copySwarmKey
config.Data["config_ipfs.sh"] = configIPFS
config.Data["init_ipfs_config.sh"] = initIPFSConfigScript
config.Data["copy_swarm_key.sh"] = copySwarmKeyScript
config.Data["config_ipfs.sh"] = configIPFSScript
}

// reconcilePVC reconciles ipfs peer persistent volume claim
Expand Down Expand Up @@ -376,6 +376,11 @@ func (r *PeerReconciler) specStatefulSet(peer *ipfsv1alpha1.Peer, sts *appsv1.St
VolumeMounts: volumeMounts,
})

// init ipfs config
profiles := []string{}
for _, profile := range peer.Spec.Profiles {
profiles = append(profiles, string(profile))
}
// config ipfs
initContainers = append(initContainers, corev1.Container{
Name: "config-ipfs",
Expand All @@ -401,6 +406,10 @@ func (r *PeerReconciler) specStatefulSet(peer *ipfsv1alpha1.Peer, sts *appsv1.St
Name: EnvIPFSGatewayHost,
Value: peer.Spec.GatewayHost,
},
{
Name: EnvIPFSProfiles,
Value: strings.Join(profiles, ";"),
},
},
Command: []string{"/bin/sh"},
Args: []string{
Expand Down
2 changes: 2 additions & 0 deletions controllers/ipfs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
EnvIPFSGatewayHost = "IPFS_GATEWAY_HOST"
// EnvIPFSInitProfiles is the environment variables used for initial profiles
EnvIPFSInitProfiles = "IPFS_INIT_PROFILES"
// EnvIPFSProfiles is the environment variables used for configuration profiles after peer intialization
EnvIPFSProfiles = "IPFS_PROFILES"

// EnvIPFSClusterPath is the environment variables used for ipfs-cluster-service path
EnvIPFSClusterPath = "IPFS_CLUSTER_PATH"
Expand Down

0 comments on commit 9eaaa73

Please sign in to comment.